C++


1.    How do you link a C++ program to C functions?

            Ans: By using the extern "C" linkage specification around the C function declarations.

2.    Explain the scope resolution operator.

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

3.    What are the differences between a C++ struct and C++ class?

            Ans: The default member and base-class access specifiers are different.

4.    How many ways are there to initialize an int with a constant?

            Ans: Two.  There are two formats for initializers in C++ as shown in the example that follows. The first format uses the traditional C                            notation. The second format uses constructor notation.
                     int foo = 123;
                     int bar (123);

5.    How does throwing and catching exceptions differ from using setjmp and longjmp?

            Ans: The throw operation calls the destructors for automatic objects instantiated since entry to the try block.

6.    What is your reaction to this line of code?
       delete this;

            Ans: It's not a good practice.

7.    What is a default constructor?

            Ans: A constructor that has no arguments.

8.    What is a conversion constructor?

            Ans: A constructor that accepts one argument of a different type.

9.    What is the difference between a copy constructor and an overloaded assignment operator?

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

10.    When should you use multiple inheritance?

            Ans: There are three acceptable answers: "Never," "Rarely," and "When the problem domain cannot be accurately modeled any                              other way."

11.    What is a virtual destructor?

            Ans: The simple answer is that a virtual destructor is one that is declared with the virtual attribute.

12.    Explain the ISA and HASA class relationships. How would you implement each in a class design?

            Ans: A specialized class "is" a specialization of another class and, therefore, has the ISA relationship with the other class. An                                    Employee ISA Person. This relationship is best implemented with inheritance. Employee is derived from Person. A class may                          have an instance of another class. For example, an employee "has" a salary, therefore the Employee class has the HASA                                relationship with the Salary class. This relationship is best implemented by embedding an object of the Salary class in the                                Employee class.

13.    When is a template a better solution than a base class?

            Ans: When you are designing a generic class to contain or otherwise manage objects of other types, when the format and behavior of                      those other types are unimportant to their containment or management, and particularly when those other types are unknown                            (thus, the genericity) to the designer of the container or manager class.

14.    What is a mutable member?

            Ans: One that can be modified by the class even when the object of the class or the member function doing the modification is const.

15.    What is an explicit constructor?

            Ans: A conversion constructor declared with the explicit keyword. The compiler does not use an explicit constructor to implement an                        implied conversion of types. It's purpose is reserved explicitly for construction.

16    What is the Standard Template Library?

            Ans: A library of container templates approved by the ANSI committee for inclusion in the standard C++ specification. A programmer                        who then launches into a discussion of the generic programming model, iterators, allocators, algorithms, and such, has a higher                      than average understanding of the new technology that STL brings to C++ programming.

17.    Describe run-time type identification.

            Ans: The ability to determine at run time the type of an object by using the typeid operator or the dynamic_cast operator.

18.    What problem does the namespace feature solve?

            Ans: Multiple providers of libraries might use common global identifiers causing a name collision when an application tries to link                            with two or more such libraries. The namespace feature surrounds a library's external declarations with a unique namespace                            that eliminates the potential for those collisions. This solution assumes that two library vendors don't use the same namespace                      identifier, of course.

19.    Are there any new intrinsic (built-in) data types?

            Ans: Yes. The ANSI committee added the bool intrinsic type and its true and false value keywords.

   20.    What is the output of printf("%d")

   21.    What will happen if I say delete this

   22.    Difference between "C structure" and "C++ structure".

   23.    Diffrence between a "assignment operator" and a "copy constructor"

   24.    What is the difference between "overloading" and "overridding"?

   25.    Explain the need for "Virtual Destructor".

   26.    Can we have "Virtual Constructors"?

   27.    What are the different types of polymorphism?

   28.    What are Virtual Functions? How to implement virtual functions in "C"

  1. What are the different types of Storage classes?

  2. What is Namespace?

  3. What are the types of STL containers?.

  4. Difference between "vector" and "array"?

  5. How to write a program such that it will delete itself after exectution?

  6. Can we generate a C++ source code from the binary file?

  7. What are inline functions?

  8. Talk sometiming about profiling?

  9. How many lines of code you have written for a single program?

  10. What is "strstream" ?

  11. How to write Multithreaded applications using C++?

  12. Explain "passing by value", "passing by pointer" and "passing by reference"

  13. Write any small program that will compile in "C" but not in "C++"

  14. Have you heard of "mutable" keyword?

  15. What is a "RTTI"?

  16. Is there something that I can do in C and not in C++?

  17. Why preincrement operator is faster than postincrement?

  18. What is the difference between "calloc" and "malloc"?

  19. What will happen if I allocate memory using "new" and free it using "free" or allocate sing "calloc" and free it using "delete"?

  20. What is Memory Alignment?

  21. Explain working of printf.

  22. Difference between "printf" and "sprintf".

  23. What is "map" in STL?

  24. When shall I use Multiple Inheritance?

  25. What are the techniques you use for debugging?

  26. How to reduce a final size of executable?

  27. Give 2 examples of a code optimization.