C++ language

FAQ
Previous Home Next
  1. How do you decide which integer type to use?
  2. What should the 64-bit integer type on new, 64-bit machines be?
  3. What’s the best way to declare and define global variables?
  4. What does extern mean in a function declaration?
  5. What’s the auto keyword good for?
  6. I can’t seem to define a linked list node which contains a pointer to itself.
  7. How do I declare an array of N pointers to functions returning pointers to functions returning pointers to characters?
  8. How can I declare a function that returns a pointer to a function of its own type?
  9. My compiler is complaining about an invalid redeclaration of a function, but I only define it once and call it once. What’s happening?
  10. What can I safely assume about the initial values of variables which are not explicitly initialized?
  11. Why can’t I initialize a local array with a string?
  12. What is the difference between char a[] = “string”; and char *p = “string”; ?
  13. How do I initialize a pointer to a function?
  14. What is Operator, Operand, Expression, Statement in 'C'?
  15. What is polymorphism?
  16. What is operator overloading?
  17. What are templates?
  18. Declare a void pointer.
  19. Declare a function pointer which takes a pointer to char as an argument and returns a void pointer.
  20. Type-define a function pointer which takes a int and float as parameter and returns a float *.
  21. What does the following C statement do?
  22. while(*c++ = *d++); assuming c and d are pointers to characters.
  23. How do you call a C module within a C++ module.
  24. What is the difference between run time binding and compile time binding? Discuss.
  25. Compare and contrast C++ and Java.
  26. Why does C/C++ give better run-time performance then Java?
  27. Does C++ come with in-built threading support.
  28. Class A derives B derives C. All have foo(). I cast C to A and call foo(). What happens?
  29. All classes A, B, C have default constructor, foo() that calls parent foo() and allocates 100 bytes to their own private local variable, and a destructor that frees the 100 bytes. I create a C object and then destroy it. What's the problem? Did all the memory get freed? What if I create C, cast to A, and then destroy it. How would I make sure memory is freed? (destructor must be virtual" and each destructor must call parent destructor)
  30. What errors are caught at compile time vs link time?
  31. What is the value of "a" after this? int (*a) [10]; a++;
  32. What is wrong with this? main(){ int *ptr; *ptr=10; }
  33. Given int n, i=10, j=20, x=3, y = 100; What is the value of n and y at the end of each of the following expressions?
    a) n = (i > j) && (x < ++y);
      b) n = (j - i) && (x < y++);
      c) n = (i < j) || (y+=i);
     int x = 5; 
      int y = 7; 
    
  34. What is the value of x and y after the expression y+=x++;
  35. What's the difference between C and C++?
  36. What does Public and Private mean in C++
  37. Is it possible to keep 2 stacks in a single array, if one grows from position one of the array, and the other grows from the last position. Write a procedure PUSH(x,s) that pushes element x onto stack S, where S is one or the other of these two stacks. Include all necessary error checks
  38. Why would you use: public/private/protected inheritance?
  39. Why does the language not define static virtual functions
  40. Can you make a destructor virtual?
  41. Why would you want a virtual destructor?
  42. How would you print the first 10 characters of a string?
  43. When would you use private inheritance?
  44. How and why would you implement a '<<' operator for a String class?
  45. When would you use a reference?
  46. Why do you want to have virtual member functions? How was "it" done before vmf's came into existence? What was wrong with it?
  47. Why is protected" as bad as ""public
  48. Give one example use of a static member.
  49. Why did new (a new expression) have to be a language-level construct while malloc could be a library function?
  50. What are the advantages and disadvantages of templates over plain old inheritance and heterogenous containers?
  51. What are the problems with a tree-style hierarchy?
  52. Why is iostream better than stdio? (There are umpteen reasons, I'm just talking about the type-safe answer/cpp.)
  53. Why would someone want to have RTTI when there are virtual functions? Doesn't that sound contradicting in purpose? Discuss one situation where RTTI could be useful, if you think so.