FreeJobAlert.Com

Government Jobs | Results | Admit Cards

Advertisement

c++ interview questions and answers | Part5

If you would like to view All C++ language interview questions only at one place visit below link

All C++ Language Interview Questions

41. Name the operators that cannot be overloaded?
Ans: sizeof, ., .*, .->, ::, ?:

42. What is an adaptor class or Wrapper class?
Ans: A class that has no functionality of its own. Its member functions hide the use of a third party software component or an object with the non-compatible interface or a non-object-oriented implementation.

43. What is a Null object?
Ans: It is an object of some class whose purpose is to indicate that a real object of that class does not exist. One common use for a null object is a return value from a member function that is supposed to return an object with some specified properties but cannot find such an object.

44. What is class invariant?
Ans: A class invariant is a condition that defines all valid states for an object. It is a logical condition to ensure the correct working of a class. Class invariants must hold when an object is created, and they must be preserved under all operations of the class. In particular all class invariants are both preconditions and post-conditions for all operations or member functions of the class.

45. What is a dangling pointer?
Ans: A dangling pointer arises when you use the address of an object after its lifetime is over. This may occur in situations like returning addresses of the automatic variables from a function or using the address of the memory block after it is freed. Example: The following code snippet shows this:
class Sample
{
public:
int *ptr;
Sample(int i)
{
ptr = new int(i);
}
~Sample()
{
delete ptr;
}
void PrintVal()
{
cout << “The value is ” << *ptr; } }; void SomeFunc(Sample x) { cout << “Say i am in someFunc ” << endl; } int main() { Sample s1= 10; SomeFunc(s1); s1.PrintVal(); } In the above example when PrintVal() function is called it is called by the pointer that has been freed by the destructor in SomeFunc. 46. Differentiate between the message and method?
Ans:
Message:
Objects communicate by sending messages to each other.
A message is sent to invoke a method.
Method
Provides response to a message and it is an implementation of an operation

47. How can we access protected and private members of a class?
Ans: In the case of members protected and private, these could not be accessed from outside the same class at which they are declared. This rule can be transgressed with the use of the friend keyword in a class, so we can allow an external function to gain access to the protected and private members of a class.

48. Can you handle exception in C++?
Ans: Yes we can handle exception in C++ using keyword: try, catch and throw. Program statements that we want to monitor for exceptions are contained in a try block. If an exception occurs within the try block, it is thrown (using throw).The exception is caught, using catch, and processed.

49. What is virtual function?
Ans: A virtual function is a member function that is declared within a base class and
redefined by a derived class .To create a virtual function, the function declaration in the base class is preceded by the keyword virtual.

50. What do you mean by early binding?
Ans:Early binding refers to the events that occur at compile time. Early binding occurs when
all information needed to call a function is known at compile time. Examples of early binding include normal function calls, overloaded function calls, and overloaded operators. The advantage of early binding is efficiency.

51. What do you mean by late binding?
Ans: Late binding refers to function calls that are not resolved until run time. Virtual functions are used to achieve late binding. When access is via a base pointer or reference, the virtual function actually called is determined by the type of object pointed to by the pointer.

Related Fresher Interview Questions

1. C Language Interview Questions
2. C++ Language Interview Questions
3. Data Structures Interview Questions
4. DBMS Interview Questions
5. Operating System Interview Questions
6. UNIX Interview Questions

Tags: aptitude question on c++, basic c++ interview questions, basic c++ interview questions and answers, basic c++ interview questions answers, c and c++ interview questions for freshers, c interview questions, c interview questions and answers, c interview questions and answers for freshers, c interview questions for freshers, c++ interview questions answers, c++ interview questions for experienced, cpp interview questions, cpp interview questions and answers, fresher interview questions, fresher interview questions and answers, fresher interview questions and answers on c and c++, fresher interview questions on c and c++, fresher interview questions with answers, interview question on c++, it fresher interview questions, it fresher interview questions and answers, objective question on c++, objective type question on c++, question on c++, questions for interview, technical question on c++, viva question on c++

Leave a Comment