Tuesday, May 29, 2007

C/C++ Faqs

  1. How do you write a program which produces its own source code as its output?
  2. Implement a queue template class using link list?
  3. What do you mean by inline function?
  4. How can I find the day of the week given the date?
  5. Why doesn’t C have nested functions?
  6. Write a program to generate the Fibonacci Series?
  7. Write a program which employs Recursion?
  8. How can I access memory located at a certain address?
  9. How can I allocate arrays or structures bigger than 64K?
  10. What is the most efficient way to count the number of bits which are set in a value?
  11. How can I return multiple values from a function?
  12. What is operator overloading?what r the advantages of operator overloading?
  13. What are inline functions?
  14. Write a program to concatenate two strings.
  15. What do you mean by inheritance?
  16. Implement a circular link list using pointers?
  17. Implement a Hash Table Abstract. Write programs for String Reversal. The same for Palindrome check.
  18. How can I invoke another program from within a C program?
  19. What is namespace?
  20. Write a program to interchange 2 variables without using the third one.
  21. What is the difference between "overloading" and "overriding"?
  22. Write a program to find the Factorial of a number.
  23. What is encapsulation?
  24. How can I convert integers to binary or hexadecimal?
  25. How can I call a function, given its name as a string?
  26. How do I access command-line arguments
  27. What’s wrong with the call fopen(”c:\newdir\file.dat”, “r”)?
  28. What will happen if I say delete this Difference between “C structure” and “C++ structure”.
  29. What is the difference between "overloading" and "overriding"?
  30. What are the different types of polymorphism?
  31. What is the output of printf(”%d”) What is encapsulation?
  32. What does static variable mean? Give 2 examples of a code optimization.
  33. What is Dangling Pointer?
  34. What are Virtual Functions?
  35. How to implement virtual functions in “C” What are the different types of Storage classes?
  36. What is a pointer?
  37. What is virtual function?
  38. What is Memory alignment?
  39. Difference between pass by reference and pass by value?
  40. Why Pointers are not used in C Language. What are the main differences between C and C++ Can we have “Virtual Constructors”?
  41. what is a smart pointer?
  42. What is auto pointer?
  43. Why should you use smart pointers?
  44. Explain in detail. What is public, protected, private?
  45. What is polymorphism? Explain with an example?
  46. When are temporary variables created by C++ compiler?
  47. Difference between a “assignment operator” and a “copy constructor”
  48. What is the difference between “overloading” and “overriding”?
  49. How to reduce a final size of executable?
  50. What is Memory Leak?
  51. What is passing by reference?
  52. What problem does the namespace feature solve?
  53. What are macros? What are the advantages and disadvantages?
  54. What is Namespace?
  55. Why does C++ have both pointers and references?
  56. Why is "this" not a reference?
  57. Is there a "placement delete"?
  58. What's wrong with arrays?
  59. What are the types of STL containers?.
  60. Can we generate a C++ source code from the binary file?
  61. What are inline functions?
  62. What is the difference between Strings and Arrays?
  63. What is encapsulation?
  64. What do you mean by binding of data and functions?
  65. In a header file whether functions are declared or defined?
  66. What is “strstream” ?
  67. What do you mean by binding of data and functions?
  68. What are the advantages of using pointers in a program?
  69. What the advantages of using Unions?
  70. Difference between “vector” and “array”?
  71. Is there something that I can do in C and not in C++?
  72. Explain “passing by value”, “passing by pointer” and “passing by reference”
  73. Have you heard of “mutable” keyword?
  74. What is a “RTTI”?
  75. What is difference between Structure and Unions?
  76. Can I stop people deriving from my class?
  77. Why doesn't C++ provide heterogeneous containers?
  78. Does "friend" violate encapsulation?
  79. Should I use NULL or 0?
  80. How are C++ objects laid out in memory?
  81. What's the value of i++ + i++?
  82. Why can't I define constraints for my template parameters?
  83. Why use sort() when we have "good old qsort()"?
  84. What is a function object?
  85. How do I deal with memory leaks
  86. How many lines of code you have written for a single program?
  87. How to write multithreaded applications using C++?
  88. How can I force objects of my class to always be created via new rather than as locals or global/static objects?
  89. Explain working of printf.
  90. What are some ways try / catch / throw can improve software quality?
  91. How do I allocate multidimensional arrays using new?
  92. What do you mean by inheritance?
  93. Does C++ have arrays whose length can be specified at run-time?
  94. What is Memory Alignment?
  95. When shall I use Multiple Inheritance?
  96. Explain whether Member Functions should be used in Smart Pointer class?
  97. what is the size of class which has int, double, and char?
  98. what are auto static variables and auto extern variables?
  99. What are the techniques you use for debugging?
  100. Implement a stack class using linked list or pointers?
  101. Implement a stack class using linked list or pointers?
  102. What's another way to build a Matrix template?
  103. What is the difference between Function and Member function?
  104. Write any small program that will compile in “C” but not in “C++”
  105. Talk something about profiling?
  106. Why preincrement operator is faster than post increment?
  107. Implement a Algorithm to check if the link list is in ascending order?
  108. What is faster ++i or i++, where i is an interger variable?
  109. How can I read a directory in a C program?
  110. Can I drop the [] when deleting array of some built-in type (char, int, etc)?
  111. How can I increase the allowable number of simultaneously open files?
  112. How do I do simple reference counting?
  113. How do I provide reference counting with copy-on-write semantics?
  114. What is friend function?
  115. Explain Storage issues of Smart Pointers?
  116. How can I find out how much memory is available?
  117. Write an algorithm to reverse a link list?
  118. How do I provide reference counting with copy-on-write semantics for a hierarchy of classes?
  119. Can you absolutely prevent people from subverting the reference counting mechanism, and if so, should you?
  120. What if I forget the [] when deleting array allocated via new k[n]?
  121. Is it legal (and moral) for a member function to say delete this?
  122. How can I handle a constructor that fails?
  123. Can I use a garbage collector in C++?
  124. What are the two kinds of garbage collectors for C++?
  125. What are the differences between a C++ struct and C++ class?
  126. What are the access privileges in C++? What is the default access level?
  127. What is a nested class? Why can it be useful?
  128. What is a local class? Why can it be useful?
  129. Can a copy constructor accept an object of the same class as parameter, instead of reference of the object?
  130. What is a class?
  131. What is near, far and huge pointers? How many bytes are occupied by them?
  132. How would you obtain segment and offset addresses from a far address of a memory location?
  133. What is diff between malloc()/free() and new/delete?
  134. What is "this" pointer?
  135. Can we take "main function" as of type float,char etc?
  136. How can we define a dynamic memory allocation in UNIX operating system?
  137. How to write a program such that it will delete itself after execution?
  138. Are the expressions arr and *arr same for an array of integers?
  139. What does extern "C" int func(int *, Foo) accomplish?
  140. How do you access the static member of a class?
  141. What is multiple inheritance(virtual inheritance)? What are its advantages and disadvantages?
  142. What are C++ storage classes?
  143. What are storage qualifiers in C++ ?
  144. What is a NULL Macro?
  145. What is the difference between a NULL Pointer and a NULL Macro?
  146. What does the error ‘Null Pointer Assignment’ mean and what causes this error?
  147. What is a NULL Pointer? Whether it is same as an uninitialized pointer?
  148. What will be output of the following program ? #include void main() { int cnt = 5, a; do { a /= cnt; } while (cnt --); printf ("%d\n", a); }
  149. What is the diff between "new" and "operator new" ?
  150. What is difference between template and macro?
  151. What is a dangling pointer?
  152. What is an object?
  153. When is an interface "good"?
  154. Print the output of this program #include void main() { int a, b, c, abc = 0; a = b = c = 40; if (c) { int abc; abc = a*b+c; } printf ("c = %d, abc = %d\n", c, abc); }
  155. Define copy constructor? What is the use of copy constructor?
  156. What is reference ??
  157. What is the use of 'using' declaration?
  158. What is encapsulation?
  159. Write down the equivalent pointer expression for referring the same element a[i][j][k][l]?
  160. How to write a program such that it will delete itself after execution?
  161. What is a far pointer? where we use it?
  162. How did you first get interested in Computer Science?
  163. What do you like to do best related to computers now (programming, administration, testing, manage projects, etc)?
  164. What is it about that area that you specifically enjoy?
  165. To which numbering system can the binary number 1101100100111100 be easily converted to?
  166. What is the use of volatile keyword? Give me one example?
  167. Find the size of an integer data type with out using sizeof() function?
  168. What is the maximum combined length of command line arguments including the space between adjacent arguments?
  169. What are the types of STL containers?
  170. Difference between a "assignment operator" and a "copy constructor"
  171. What is virtual class and friend class?
  172. Are the variables argc and argv are local to main?
  173. Which bit wise operator is suitable for checking whether a particular bit is on or off?
  174. Which bit wise operator is suitable for turning off a particular bit in a number?
  175. Does there exist any way to make the command line arguments available to other functions without passing them as arguments to the function?
  176. What are bit fields? What is the use of bit fields in a Structure declaration?
  177. If we want that any wildcard characters in the command line arguments should be appropriately expanded, are we required to make any special provision? If yes, which?
  178. What is the difference between structures and classes in C++?
  179. How can double dimensional arrays be dynamically initialized in C++?
  180. What is difference between constructor and destructor
    #define f(a,b) a+
    #define g(a,b) a*b
    main()
    {
    int m;
    m=2*f(3,g(4,5));
    printf(" m is %d",m);
    }
    what's the value of m
    a.70
    b.50
    c.26
    d. 69
  181. How would you use the functions sin(), pow(), sqrt()?
  182. Is it safe to delete the same pointer twice?
  183. Can I free() pointers allocated with new? Can I delete pointers allocated with malloc()?
  184. Why should I use new instead of trustworthy old malloc()?
  185. Can I use realloc() on pointers allocated via new?
  186. What is the difference between class and structure?
  187. What is the difference between macro and inline()?
  188. How would you use the functions randomize() and random()?
  189. How would you implement a substr() function that extracts a sub string from a given string?
  190. What is the difference between the functions rand(), random(), srand() and randomize()?
  191. What is the difference between the functions memmove() and memcpy()?
  192. How would you obtain the current time and difference between two times?
  193. What is difference between copy constructor and constructor?
  194. How do you print a string on the printer?
  195. Can you use the function fprintf() to display the output on the screen?
  196. Why can't I resume after catching an exception?
  197. How would you use the functions memcpy(), memset(), memmove()?
  198. Is it safe to delete the same pointer twice?
  199. Write a program to calculate number of 1's (bit) in a given integer number i.e) Number of 1's in the given integer's equivalent binary representation.
  200. Why are destructors not virtual by default?
  201. Why don't we have virtual constructors?
  202. Differentiate between a for loop and a while loop? What are it uses?
  203. What are the different storage classes in C?
  204. Do I need to check for NULL after p = new Fred()?
  205. How can I convince my (older) compiler to automatically check new to see if it returns NULL?
  206. How do I allocate / unallocate an array of things?
  207. Do I need to check for NULL before delete p?
  208. What are the two steps that happen when I say delete p?
  209. In p = new Fred(), does the Fred memory "leak" if the Fred constructor throws an exception?
  210. How would you use the functions fseek(), freed(), fwrite() and ftell()?
  211. Why doesn't overloading work for derived classes?
  212. Can I call a virtual function from a constructor?
  213. What will be the output of this program ?
    #include main()
    { int *a, i; a = (int *) malloc(10*sizeof(int));
    for (i=0; i<10; i="0;">
  214. How would you dynamically allocate a one-dimensional and two-dimensional array of integers?
  215. Can you write a function similar to printf()?
  216. What is the difference between a pointer and a reference?
  217. How are prefix and postfix versions of operator++() differentiated?
  218. Can you dynamically allocate arrays in expanded memory?
  219. Which function should be used to free the memory allocated by calloc()?
  220. How much maximum can you allocate in a single call to malloc()?
  221. How can a called function determine the number of arguments that have been passed to it?
  222. Can there be at least some solution to determine the number of arguments passed to a variable argument list function?
  223. When do use "const" reference arguments in function?
  224. How can you increase the size of a dynamically allocated array?
  225. What is copy constructor?
  226. When are copy constructors called?
  227. How can you increase the size of a statically allocated array?
  228. What is object file? How can you access object file?
  229. Which header file should you include if you are to develop a function which can accept variable number of arguments?
  230. When reallocating memory if any other pointers point into the same piece of memory do you have to readjust these other pointers or do they get readjusted automatically?
  231. What is the difference between const char *myPointer and char *const myPointer?
  232. How can I handle a constructor that fails?
  233. Can you overload a function based only on whether a parameter is a value or a reference?
  234. How does C++ help with the tradeoff of safety vs. usability?
  235. How can I prevent other programmers from violating encapsulation by seeing the private parts of my class?
  236. Is Encapsulation a Security device?
  237. What is assignment operator?
  238. In header files whether functions are declared or defined?
  239. What is a structure?
  240. Explain the need for “Virtual Destructor”.
  241. What is Polymorphism?
  242. How can I handle a destructor that fails?
  243. What is Virtual Destructor?
  244. Can you think of a situation where your program would crash without reaching the breakpoint which you set at the beginning of main()?
  245. Name two cases where you MUST use initialization list as opposed to assignment in constructors.
  246. What is constructor or ctor?
  247. What is destructor?
  248. What is encapsulation?
  249. What is pure virtual function? or what is abstract class?
  250. What are the differences between structures and arrays?
  251. How can I write/read objects of my class to/from a data file?
  252. How can I send objects of my class to another computer (e.g., via a socket, TCP/IP, FTP, email, a wireless link, etc.)?
  253. Why can't I open a file in a different directory such as "..\test.dat"?
  254. What is default constructor?
  255. What are the differences between malloc() and calloc()?
  256. What's the difference between the keywords struct and class?
  257. How can I tell {if a key, which key} was pressed before the user presses the ENTER key?
  258. How can I make it so keys pressed by users are not echoed on the screen?
  259. Does delete p delete the pointer p, or the pointed-to-data *p?
  260. In c++ have a default constructor ?
  261. How do you write a program which produces its own source code as its output?
  262. what is memory leaking in c++ ?
  263. Why cant one make an object of abstract class?Give compiler view of statement
  264. what is the difference betwen wait() and delay()?
  265. What are Virtual Functions? How to implement virtual functions in "C"
  266. What is virtual constructors/destructors?
    int f(int *a)
    {
    int b=5;
    a=&b;
    }
    main()
    {
    int i;
    printf(" %d",i);
    f(&i);
    printf(" %d",i);
    }
    what's the output .
    1.10,5
    2,10,10
    c.5,5
    d. none
  267. How do I use exceptions?
  268. Write the hello world program . . . Without using any semi-colon's ";" ?
  269. How does free know the size of memory to be deleted? int *i = (int *)malloc(12); followed by free(i); how did free function call know how much of memory to delete?
  270. Write a function to display an integer in a binary format.
  271. Implement Binary Search Tree in C++?
  272. Why doesn't C++ have an equivalent to realloc()?
  273. Why are member functions not virtual by default?
  274. What is the similarity between a Structure, Union and enumeration?
  275. Write the output of this program #include #define calc(a, b) (a * b) / (a - b) void main() { int a = 20, b = 10; printf("%d\n", calc(a + 4, b -2)); }
  276. What is an Iterator class?
  277. Implement Binary Heap in C++?
  278. Implement Vector class in C++?
  279. Implement STL List template class in C++? STL List class is a doubly linked list with a head and a tail pointer.
  280. Why doesn't C++ have a universal class Object?
  281. How do I read a string from input?
  282. Implementation of string length using pointer hopping
  283. Why is the size of an empty class not zero?
  284. Why do I have to put the data in my class declarations?
  285. Write a program to swap two integers without using 3rd integer (ie. Without using any temporary variable)
  286. Write a general swap macro in C : - A macro which can swap any type of data (ie. int, char, float, struct, etc..)
  287. What is a reference?
    What happens if you assign to a reference?
  288. Why can't I initialize my static member data in my constructor's initialization list?
  289. Should my constructors use "initialization lists" or "assignment"?
  290. Implementation of Random number generator?
  291. Implement Tic-Tac Game in C++?
  292. What happens if you return a reference?
  293. How can you reseat a reference to make it refer to a different object?
  294. When should I use references, and when should I use pointers?
  295. What is a handle to an object? Is it a pointer? Is it a reference? Is it a pointer-to-a-pointer? What is it?
  296. What is the "Named Constructor Idiom"?
  297. Does return-by-value mean extra copies and extra overhead?
  298. But can I explicitly call a destructor if I've allocated my object with new?
  299. What is "placement new" and why would I use it?
  300. Can one constructor of a class call another constructor of the same class to initialize the this object?
  301. When I write a derived class's destructor, do I need to explicitly call the destructor for my base class?
  302. Should my destructor throw an exception when it detects a problem?
  303. Why can't I assign a vector to a vector?
  304. Should you use this pointer in the constructor?
  305. When I write a destructor, do I need to explicitly call the destructors for my member objects?
  306. Why are classes with static data members getting linker errors?
  307. What if I can't wrap the local in an artificial block?
  308. Is there a way to force new to allocate memory from a specific memory area?
    main()
    {
    int i;
    fork();
    fork();
    fork();
    printf("----");
    }
    how many times the printf will be executed .
    a.3
    b. 6
    c.5
    d. 8

4 comments:

muli said...

1. what are the main defferences between an array and a C++ vector? explain with examples.

2. what is the defferences between between a function template and templete function? explain with examples.

muli said...

what are the different pre-processor firectives in C++? what are their advantages?

muli said...

write a program that reads full names , one per line and then prints them in the standard telephone directory format.

muli said...

what are the different pre-processor directives in C++? what are their advantages?