Wednesday, 11 February 2015

Most frequently asked C Plus Plus Interview Questions and Answers (Page 4)

Below are some important C++ interview questions which are asked in most MNC company interviews for beginners or professionals.

31. What do you mean by binding of data and functions?

32. What is friend function in C++?
As the name suggests, the function acts as a friend to a class. As a friend of a class, it can access its private and protected members. A friend function is not a member of the class. But it must be listed in the class definition.

33. What is abstraction in C++?
Abstraction is of the process of hiding unwanted details from the user.

34. What are virtual functions in C++?
A virtual function allows derived classes to replace the implementation provided by the base class. The compiler makes sure the replacement is always called whenever the object in question is actually of the derived class, even if the object is accessed by a base pointer rather than a derived pointer. This allows algorithms in the base class to be replaced in the derived class, even if users don't know about the derived class.

35. What is a scope resolution operator?
A scope resolution operator (::), can be used to define the member functions of a class outside the class.

36. What do you mean by pure virtual functions?
A pure virtual member function is a member function that the base class forces derived classes to provide. Normally these member functions have no implementation. Pure virtual functions are equated to zero. class Shape { public: virtual void draw() = 0; };

37. What is polymorphism in C++? Explain with an example?
"Poly" means "many" and "morph" means "form". Polymorphism is the ability of an object (or reference) to assume (be replaced by) or become many different forms of object. Example: function overloading, function overriding, virtual functions. Another example can be a plus '+' sign, used for adding two integers or for using it to concatenate two strings.

38. What is the best way to declare and define global variables?
The best way to declare global variables is to declare them after including all the files so that it can be used in all the functions.

39. What does extern mean in a function declaration in C++?
It tells the compiler that a variable or a function exists, even if the compiler hasn't yet seen it in the file currently being compiled. This variable or function may be defined in another file or further down in the current file.

40. Explain the scope resolution operator.
It permits a program to reference an identifier in the global scope that has been hidden by another identifier with the same name in the local scope.
More Questions & Answers :-

No comments:

Post a Comment