April 29, 2013

C/C++ Programming interview questions and answers

What is the difference between a pointer and a reference? Ans- A reference must always refer to some object and, therefore, must always be initialized; pointers do not have such restrictions. A pointer can be reassigned to point to different objects while a reference always refers to an object with which it was initialized.


How are prefix and postfix versions of operator++() differentiated?
Ans- The postfix version of operator++() has a
dummy parameter of type int. The prefix version does not have dummy parameter.


What is name mangling in C++??
Ans- The process of encoding the parameter types with the function/method name into a unique name is called name mangling. The inverse process is called demangling.
For example Foo::bar(int, long) const is mangled as `bar__C3Fooil'.
For a constructor, the method name is left out. That is Foo::Foo(int, long) const is mangled as `__C3Fooil'.


What is the difference between const char *myPointer and char *const myPointer?
Ans- Const char *myPointer is a non constant pointer to constant data; while char *const myPointer is a constant pointer to non constant data.


How can I handle a constructor that fails?
Ans- throw an exception. Constructors don't have a return type, so it's not possible to use return codes. The best way to signal constructor failure is therefore to throw an exception.

0 comments:

Post a Comment

  • Blogger news

    This Blog Contains All Topics Related To Internet, Website Help, Interview Questions, News, Results From Various Resources, Visit Daily For More Interesting And Famous Topics.
  • Random Post

  • About

    We Provide All Information Which you Needed. We Maintain This Blog Very Carefully, If You Find Any Mistake or Any Suggestions Then Please Let Us Know, You Can Contact Us By Comments, On FB Page Or On Google+ Page. ~ Thank You