Select chapter



constructors (2.papers)
inheritance (1.papers)
overriding (1.papers)
basics (4.papers)
pointers (2.papers)
Hide

Sponsored Links


  

c++ interview questions and answers

1
What is auto_ptr?
  1. a pointer to a variable which is declared as auto.
  2. it is same as normal pointer.
  3. it is a template class, which has the similar functionality of a pointer , but it will take care of memory leaks.
  4. a dangling pointer is called as auto_ptr.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
3
What is the output of below C++ program?
char *p = NULL;
int main()
{
    *p = 100;
    cout<<*p;
}
  1. NULL
  2. 100
  3. Run time error, Invalid memory reference. Or it may even crash at run time.
  4. Compile time error, we can't de-reference a null pointer?
Show Answer
Share Facebook gmail Twitter
4
What is the output of below C++ program?
int main()
{
    int a = 10;
    int &b = a;
    b++;
    cout<<a;
}
  1. 10
  2. 11
  3. garbage value or it may crash at run time.
  4. compile time error at  int &b = a; invalid syntax.
Show Answer
Share Facebook gmail Twitter
5
Once a reference variable is created, can it refer to other object? 
  1. yes, why not.
  2. No. Once references are created it is done. We can't re reference it to other object.
  3. we can't say
  4. none
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
7
Which of the below statements are false?
  1. it is possible to create a pointer to a reference.
  2. we can't have array of references.
  3. we can't have reference to a reference.
  4. it is possible to have pointer to a pointer.
Show Answer
Share Facebook gmail Twitter
8
what is the difference between const char *p; and char * const q;
  1. both are same.
  2. p is a constant character pointer, and q is a constant pointer to a character.
  3. p is a pointer to constant character, and q is a constant pointer to a character.
  4. p is a pointer to constant character, and q is a constant pointer to a constant character.
Show Answer
Share Facebook gmail Twitter
9
What is memory leak?
  1. holding the address of an object, whose life time is already over.
  2. you have dynamically allocated some heap, and you are trying to free it more than once.
  3. you have dynamically allocated some heap, but you don't have any pointer reference to it to free.
  4. a pointer which is assigned with null.
Show Answer
Share Facebook gmail Twitter
Show Answer
Share Facebook gmail Twitter
11
What is the difference between a reference and a pointer?
  1. 1. a pointer can be null pointer, but there is null reference concept.  2. A reference should be initialized else it is a compile time error. But a pointer is not required to be initialized.
  2. 1. A pointer can be reinitialized, but a reference can't. 2. We can create a pointer to a pointer, but we can't reference to another reference object.
  3. both option 1 & 2 are true
  4. none
Show Answer
Share Facebook gmail Twitter
Read more papers :