Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

C++ Interview Questions and Answers

Test your skills through the online practice test: C++ Quiz Online Practice Test

Related differences

C vs C++Java vs C++

Ques 101. What is an incomplete type?


Incomplete types refers to pointers in which there is non availability of the implementation of the referenced location or it points to some location whose value is not available for modification.

int *i=0x400 // i points to address 400
*i=0; //set the value of memory location pointed by i.

Incomplete types are otherwise called uninitialized pointers.

Is it helpful? Add Comment View Comments
 

Ques 102. What is a dangling pointer?


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. 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.

Is it helpful? Add Comment View Comments
 

Ques 103. Differentiate between the message and method.

Message:
* Objects communicate by sending messages to each other.
* A message is sent to invoke a method.

Method
* Provides response to a message.
* It is an implementation of an operation.

Is it helpful? Add Comment View Comments
 

Ques 104. What is an adaptor class or Wrapper class?


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.

Is it helpful? Add Comment View Comments
 

Ques 105. What is a Null object?


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.
 

Is it helpful? Add Comment View Comments
 

4) What is an adaptor class or Wrapper class? 5) What is a Null object? " />

Most helpful rated by users:

©2024 WithoutBook