CPlusPlus Interview Questions and Answers
Question - 61 : - How does throwing and catching exceptions differ from using setjmp and longjmp?
Answer - 61 : - The throw operation calls the destructors for automatic objects instantiated since entry to the try block.
Question - 62 : - What is a default constructor?
Answer - 62 : - Default constructor WITH arguments class B { public: B (int m = 0) : n (m) {} int n; }; int main(int argc, char *argv[]) { B b; return 0; }
Question - 63 : - What is a conversion constructor?
Answer - 63 : - A constructor that accepts one argument of a different type.
Question - 64 : - How do I declare an array of N pointers to functions returning pointers to functions returning pointers to characters?
Answer - 64 : - 1.
If you want the code to be even slightly readable, you will use typedefs.
typedef char* (*functiontype_one)(void);
typedef functiontype_one (*functiontype_two)(void);
functiontype_two myarray[N]; //assuming N is a const integral
2.
char* (* (*a[N])())()
Here a is that array. And according to question no function will not take any parameter value.
Question - 65 : - Explain the scope resolution operator.
Answer - 65 : - 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.
Question - 66 : - What are the differences between a C++ struct and C++ class?
Answer - 66 : - The default member and base-class access specifier are different.
Question - 67 : - How do you link a C++ program to C functions?
Answer - 67 : - By using the extern "C" linkage specification around the C function declarations.
Question - 68 : - What does extern mean in a function declaration?
Answer - 68 : - 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.
Question - 69 : - What is the difference between a copy constructor and an overloaded assignment operator?
Answer - 69 : - A copy constructor constructs a new object by using the content of the argument object. An overloaded assignment operator assigns the contents of an existing object to another existing object of the same class.
Question - 70 : - When should you use multiple inheritance?
Answer - 70 : - There are three acceptable answers: "Never," "Rarely," and "When the problem domain cannot be accurately modeled any other way."