You are on page 1of 10

New!! What is Dangling Pointer?

New!! What is Memory Leak?


New!! what is a smart pointer?
New!! What is auto pointer?
New!! Why should you use smart pointers?. Explain in detail.
New!! Explain Storage issues of Smart Pointers?
New!! Explain whether Member Functions should be used in Smart Pointer class?
New!! what is the size of class which has int, double, and char?
New!! What is faster ++i or i++, where i is an interger variable?
New!! what happens if you write this code? string& foo() { return "Hello World"; } cout << foo() << endl;
New!! 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?
New!! Write a function to display an integer in a binary format.
New!! Implement Binary Search Tree in C++?
New!! Implement Binary Heap in C++?
New!! Implement Vector class in C++?
New!! Implement STL List template class in C++? STL List class is a doubly linked list with a head and a tail
pointer.
New!! Implementation of Random number generator?
New!! Implement TicTac Game in C++?
New!! Implementation of string length using pointer hopping
New!! Why is the size of an empty class not zero?
New!! Why do I have to put the data in my class declarations?
New!! Why are member functions not virtual by default?
New!! Why are destructors not virtual by default?
New!! Why don't we have virtual constructors?
New!! Why doesn't overloading work for derived classes?
New!! Can I call a virtual function from a constructor?
New!! Is there a "placement delete"?
New!! Can I stop people deriving from my class?
New!! Why doesn't C++ provide heterogenous containers?
New!! Does "friend" violate encapsulation?
New!! Why does C++ have both pointers and references?
New!! Why is "this" not a reference?
New!! What's wrong with arrays?
New!! Should I use NULL or 0?
New!! How are C++ objects laid out in memory?
New!! What's the value of i++ + i++?
New!! Why can't I define constraints for my template parameters?
New!! Why use sort() when we have "good old qsort()"?
New!! What is a function object?
New!! How do I deal with memory leaks?
New!! Why can't I resume after catching an exception?
New!! Why doesn't C++ have an equivalent to realloc()?
New!! How do I use exceptions?
New!! Why can't I assign a vector<Apple*> to a vector<Fruit*>?
New!! Why doesn't C++ have a universal class Object?
New!! How do I read a string from input?
New!! Why doesn't C++ provide a "finally" construct?
New!! What is an auto_ptr and why isn't there an auto_array?
New!! Can I mix C-style and C++ style allocation and deallocation?
New!! Why must I use a cast to convert from void*?
New!! How do I define an in-class constant?
New!! Why doesn't delete zero out its operand?
New!! Why isn't the destructor called at the end of scope?
New!! Can I write "void main()"?
New!! Why can't I overload dot, ::, sizeof, etc.?
New!! How do I convert an integer to a string?
New!! How do I call a C function from C++?
New!! How do I call a C++ function from C?
New!! Is ``int* p;'' right or is ``int *p;'' right?
New!! Should I put "const" before or after the type?
New!! What good is static_cast?
New!! What good is static_cast?
New!! what's wrong with using macros?
New!! Write the hello world program . . . Without using any semi-colon's ";" ?
New!! Write the output of the following program #include #define ABC 20 #define XYZ 10 #define XXX ABC -
XYZ void main() { int a; a = XXX * 10; printf("%d\n", a); }
New!! 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)); }
New!! What will be output of the following program ? #include void main() { int cnt = 5, a; do { a /= cnt; } while
(cnt --); printf ("%d\n", a); }
New!! 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); }
New!! Print the output of this program #include main() { int k = 5; if (++k < 5 && k++/5 || ++k <= 8);
printf("%d\n", k); }
New!! What is the output of this program ? #include void fn(int, int); main() { int a = 5; printf("Main : %d %d\n",
a++, ++a); fn(a, a++); } void fn(int a, int b) { printf("Fn : a = %d \t b = %d\n", a, b); }
New!! Write the output of this program #include main() { int *a, *s, i; s = a = (int *) malloc( 4 * sizeof(int)); for
(i=0; i<4; i++) *(a+i) = i * 10; printf("%d\n", *s++); printf("%d\n", (*s)++); printf("%d\n", *s); printf("%d\n", *++s);
printf("%d\n", ++*s); }
New!! Checkout this program result #include void fn(int); static int val = 5; main() { while (val --) fn(val);
printf("%d\n", val); } void fn(int val) { static int val = 0; for (; val < 5; val ++) printf("%d\n", val); }
New!! Can you predict the output of this program ? #include main() { typedef union { int a; char b[10]; float c; }
Union; Union x, y = { 100 }; x.a = 50; strcpy (x.b, "hello"); x.c = 21.50; printf ("Union 2 : %d %s %f\n", x.a, x.b, x.c); printf
("Union Y : %d %s %f\n", y.a, y.b, y.c); }
New!! Print the output of the program #include main() { struct Data { int a; int b; } y[4] = { 1, 10, 3, 30, 2, 20, 4,
40}; struct Data *x = y; int i; for(i=0; i<4; i++) { x->a = x->b, ++x++->b; printf("%d %d\t", y[i].a, y[i].b); } }
New!! Write the output of this program #include main() { typedef struct { int a; int b; int c; char ch; int d; }xyz;
typedef union { xyz X; char y[100]; }abc; printf("sizeof xyz = %d sizeof abc = %d\n", sizeof(xyz), sizeof(abc)); }
New!! Find out the error in this code #include #include #define Error(str) printf("Error : %s\n", str); exit(1); main()
{ int fd; char str[20] = "Hello! Test me"; if ((fd = open("xx", O_CREAT | O_RDWR)) < 0) Error("open failed"); if (write(fd, str,
strlen(str)) < 0) Error("Write failed"); if (read(fd, str, strlen(str)) < 0) Error("read failed"); printf("File read : %s\n", str); close(fd);
}
New!! 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++) *(a + i) = i * i; for (i=0; i<10; i++) printf("%d\t", *a++); free(a); }
New!! 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.
New!! Write a function revstr() - which reverses the given string in the same string buffer using pointers. (ie)
Should not use extra buffers for copying the reverse string.
New!! Write a program to print the series 2 power x, where x >= 0 ( 1, 2, 4, 8, 16, .... ) without using C math library
and arithmatic operators ( ie. *, /, +, - and math.h are not allowed)
New!! Write a program to swap two integers without using 3rd integer (ie. Without using any temporary variable)
New!! Write a general swap macro in C : - A macro which can swap any type of data (ie. int, char, float, struct,
etc..)
New!! Write a program to delete the entry from the doubly linked list without saving any of the entries of the list to
the temporary variable.
New!! What will be the output of this program ? #include main() { int *a, *savea, i; savea = a = (int *) malloc(4 *
sizeof(int)); for (i=0; i<4; i++) *a++ = 10 * i; for (i=0; i<4; i++) { printf("%d\n", *savea); savea += sizeof(int); } }
New!! Trace the program and print the output #include typedef int abc(int a, char *b); int func2(int a, char *b) { a
*= 2; strcat(b, "func2 "); return a; } int func1(int a, char *b) { abc *fn = func2; a *= a; strcat(b, "func1 "); return (fn(a, b)); }
main() { abc *f1, *f2; int res; static char str[50] = "hello! "; f1 = func1; res = f1(10, str); f1 = func2; res = f1(res, str); printf("res :
%d str : %s\n", res, str); }
New!! Write a program to reverse a Linked list within the same list
New!! What will be the output of this program #include main() { int a=3, b = 5; printf(&a["Ya!Hello! how is this?
%s\n"], &b["junk/super"]); printf(&a["WHAT%c%c%c %c%c %c !\n"], 1["this"],
2["beauty"],0["tool"],0["is"],3["sensitive"],4["CCCCCC"]); }
What is inheritance?
What is encapsulation?
What is Polymorphism?
What is constructor or ctor?
What is destructor?
What is default constructor?
What is copy constructor?
When are copy constructors called?
What is assignment operator?
What are all the implicit member functions of the class? Or what are all the functions which compiler implements
for us if we don't define one.??
What is conversion constructor?
What is conversion operator?
What is diff between malloc()/free() and new/delete?
what is the diff between "new" and "operator new" ?
What is difference between template and macro?
What are C++ storage classes?
What are storage qualifiers in C++ ?
What is reference ??
What is passing by reference?
When do use "const" reference arguments in function?
When are temporary variables created by C++ compiler?
What is virtual function?
What is pure virtual function? or what is abstract class?
What is Memory alignment?
What problem does the namespace feature solve?
What is the use of 'using' declaration?
What is an Iterator class?
What is a dangling pointer?
What do you mean by Stack unwinding?
Name the operators that cannot be overloaded??
What is a container class? What are the types of container classes?
What is inline function?
What is overloading?
What is Overriding?
What is "this" pointer?
What happens when you make call "delete this;" ?
How virtual functions are implemented C++?
What is name mangling in C++?
What is the difference between a pointer and a reference?
How are prefix and postfix versions of operator++() differentiated?
What is the difference between const char *myPointer and char *const myPointer?
How can I handle a constructor that fails?
How can I handle a destructor that fails?
What is Virtual Destructor?
Can you think of a situation where your program would crash without reaching the breakpoint which you set at the
beginning of main()?
Name two cases where you MUST use initialization list as opposed to assignment in constructors.
Can you overload a function based only on whether a parameter is a value or a reference?
What are the differences between a C++ struct and C++ class?
What does extern "C" int func(int *, Foo) accomplish?
How do you access the static member of a class?
What is multiple inheritance(virtual inheritance)? What are its advantages and disadvantages?
What are the access privileges in C++? What is the default access level?
What is a nested class? Why can it be useful?
What is a local class? Why can it be useful?
Can a copy constructor accept an object of the same class as parameter, instead of reference of the object?
What is a class?
What is an object?
When is an interface "good"?
What is encapsulation?
How does C++ help with the tradeoff of safety vs. usability?
How can I prevent other programmers from violating encapsulation by seeing the private parts of my class?
Is Encapsulation a Security device?
What's the difference between the keywords struct and class?
What is a reference?
What happens if you assign to a reference?
What happens if you return a reference?
What does object.method1().method2() mean?
How can you reseat a reference to make it refer to a different object?
When should I use references, and when should I use pointers?
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?
What's the deal with inline functions?
What's a simple example of procedural integration?
Do inline functions improve performance?
How can inline functions help with the tradeoff of safety vs. speed?
Why should I use inline functions instead of plain old #define macros?
How do you tell the compiler to make a non-member function inline?
How do you tell the compiler to make a member function inline?
Is there another way to tell the compiler to make a member function inline?
With inline member functions that are defined outside the class, is it best to put the inline keyword next to the
declaration within the class body, next to the definition outside the class body, or both?
What's the deal with constructors?
Is there any difference between List x; and List x();?
Can one constructor of a class call another constructor of the same class to initialize the this object?
Is the default constructor for Fred always Fred::Fred()?
Which constructor gets called when I create an array of Fred objects?
Should my constructors use "initialization lists" or "assignment"?
Should you use the this pointer in the constructor?
What is the "Named Constructor Idiom"?
Does return-by-value mean extra copies and extra overhead?
Why can't I initialize my static member data in my constructor's initialization list?
Why are classes with static data members getting linker errors?
What's the "static initialization order fiasco"?
How do I prevent the "static initialization order fiasco"?
Why doesn't the construct-on-first-use idiom use a static object instead of a static pointer?
How do I prevent the "static initialization order fiasco" for my static data members?
Do I need to worry about the "static initialization order fiasco" for variables of built-in/intrinsic types?
How can I handle a constructor that fails?
What is the "Named Parameter Idiom"?
Why am I getting an error after declaring a Foo object via Foo x(Bar())?
What's the deal with destructors?
What's the order that local objects are destructed?
What's the order that objects in an array are destructed?
Can I overload the destructor for my class?
Should I explicitly call a destructor on a local variable?
What if I want a local to "die" before the close } of the scope in which it was created? Can I call a destructor on a
local if I really want to?
OK, OK already; I won't explicitly call the destructor of a local; but how do I handle the above situation?
What if I can't wrap the local in an artificial block?
But can I explicitly call a destructor if I've allocated my object with new?
What is "placement new" and why would I use it?
When I write a destructor, do I need to explicitly call the destructors for my member objects?
When I write a derived class's destructor, do I need to explicitly call the destructor for my base class?
Should my destructor throw an exception when it detects a problem?
Is there a way to force new to allocate memory from a specific memory area?
What is "self assignment"?
Why should I worry about "self assignment"?
OK, OK, already; I'll handle self-assignment. How do I do it?
What's the deal with operator overloading?
What are the benefits of operator overloading?
What are some examples of operator overloading?
But operator overloading makes my class look ugly; isn't it supposed to make my code clearer?
What operators can/cannot be overloaded?
Can I overload operator== so it lets me compare two char[] using a string comparison?
Can I create a operator** for "to-the-power-of" operations?
Okay, that tells me the operators I can override; which operators should I override?
What are some guidelines / "rules of thumb" for overloading operators?
How do I create a subscript operator for a Matrix class?
Why shouldn't my Matrix class's interface look like an array-of-array?
I still don't get it. Why shouldn't my Matrix class's interface look like an array-of-array?
Should I design my classes from the outside (interfaces first) or from the inside (data first)?
How can I overload the prefix and postfix forms of operators ++ and --?
Which is more efficient: i++ or ++i?
What is a friend?
Do friends violate encapsulation?
What are some advantages/disadvantages of using friend functions?
What does it mean that "friendship isn't inherited, transitive, or reciprocal"?
Should my class declare a member function or a friend function?
Why should I use <iostream> instead of the traditional <cstdio>?
Why does my program go into an infinite loop when someone enters an invalid input character?
How can I get std::cin to skip invalid input characters?
How does that funky while (std::cin >> foo) syntax work?
Why does my input seem to process past the end of file?
Why is my program ignoring my input request after the first iteration?
Should I end my output lines with std::endl or '\n'?
How can I provide printing for my class Fred?
But shouldn't I always use a printOn() method rather than a friend function?
How can I provide input for my class Fred?
How can I provide printing for an entire hierarchy of classes?
How can I open a stream in binary mode?
How can I "reopen" std::cin and std::cout in binary mode?
How can I write/read objects of my class to/from a data file?
How can I send objects of my class to another computer (e.g., via a socket, TCP/IP, FTP, email, a wireless link,
etc.)?
Why can't I open a file in a different directory such as "..\test.dat"?
How can I tell {if a key, which key} was pressed before the user presses the ENTER key?
How can I make it so keys pressed by users are not echoed on the screen?
Does delete p delete the pointer p, or the pointed-to-data *p?
Is it safe to delete the same pointer twice?
Is it safe to delete the same pointer twice?
Can I free() pointers allocated with new? Can I delete pointers allocated with malloc()?
Why should I use new instead of trustworthy old malloc()?
Can I use realloc() on pointers allocated via new?
Do I need to check for NULL after p = new Fred()?
How can I convince my (older) compiler to automatically check new to see if it returns NULL?
Do I need to check for NULL before delete p?
What are the two steps that happen when I say delete p?
In p = new Fred(), does the Fred memory "leak" if the Fred constructor throws an exception?
How do I allocate / unallocate an array of things?
What if I forget the [] when deleteing array allocated via new T[n]?
Can I drop the [] when deleteing array of some built-in type (char, int, etc)?
After p = new Fred[n], how does the compiler know there are n objects to be destructed during delete[] p?
Is it legal (and moral) for a member function to say delete this?
How do I allocate multidimensional arrays using new?
But the previous FAQ's code is SOOOO tricky and error prone! Isn't there a simpler way?
But the above Matrix class is specific to Fred! Isn't there a way to make it generic?
What's another way to build a Matrix template?
Does C++ have arrays whose length can be specified at run-time?
How can I force objects of my class to always be created via new rather than as locals or global/static objects?
How do I do simple reference counting?
How do I provide reference counting with copy-on-write semantics?
How do I provide reference counting with copy-on-write semantics for a hierarchy of classes?
Can you absolutely prevent people from subverting the reference counting mechanism, and if so, should you?
Can I use a garbage collector in C++?
What are the two kinds of garbage collectors for C++?
What are some ways try / catch / throw can improve software quality?
How can I handle a constructor that fails?
How can I handle a destructor that fails?
How should I handle resources if my constructors may throw exceptions?
How do I change the string-length of an array of char to prevent memory leaks even if/when someone throws an
exception?
What should I throw?
What should I catch?
But MFC seems to encourage the use of catch-by-pointer; should I do the same?
What does throw; (without an exception object after the throw keyword) mean? Where would I use it?
How do I throw polymorphically?
When I throw this object, how many times will it be copied?
Exception handling seems to make my life more difficult; clearly I'm not the problem, am I??
I have too many try blocks; what can I do about it?
Write a program Sorting With the sort() Algorithm.?
What a derived class inherits or doesn't inherit?
What a derived class can add?
What happens when a derived-class object is created and destroyed?
Design a C++ Class for Playing Cards?
Implement a Complete multiplayer Black Jack Game in C++ using cards and Deck classes previously developed?
Design and Implement a Pointer Based LinkList class using templates?
Write an algorithm to reverse a link list?
Implement a Algorithm to check if the link list is in Ascending order?
Implement a stack class using linked list or pointers?
Implement a queue template class using link list?
Implement a circular link list using pointers?
Implement a Hash Table Abstract data structure using link list?
Find the size of an interger data type with out using sizeof() function?

1. What does static variable mean?


2. What is a pointer?
3. What is a structure?
4. What are the differences between structures and arrays?
5. In header files whether functions are declared or defined?
6. What are the differences between malloc() and calloc()?
7. What are macros? What are the advantages and disadvantages?
8. Difference between pass by reference and pass by value?
9. What is static identifier?
10. Where are the auto variables stored?
11. Where does global, static, local, register variables, free memory and C Program
instructions get stored?
12. Difference between arrays and linked list?
13. What are enumerations?
14. Describe about storage allocation and scope of global, extern, static, local and register
variables?
15. What are register variables? What are the advantage of using register variables?
16. What is the use of typedef?
17. Can we specify variable field width in a scanf() format string? If possible how?
18. Out of fgets() and gets() which function is safe to use and why?
19. Difference between strdup and strcpy?
20. What is recursion?
21. Differentiate between a for loop and a while loop? What are it uses?
22. What are the different storage classes in C?
23. Write down the equivalent pointer expression for referring the same element a[i][j][k][l]?
24. What is difference between Structure and Unions?
25. What the advantages of using Unions?
26. What are the advantages of using pointers in a program?
27. What is the difference between Strings and Arrays?
28. In a header file whether functions are declared or defined?
29. What is a far pointer? where we use it?
30. How will you declare an array of three function pointers where each function receives
two ints and returns a float?
31. What is a NULL Pointer? Whether it is same as an uninitialized pointer?
32. What is a NULL Macro? What is the difference between a NULL Pointer and a NULL
Macro?
33. What does the error ‘Null Pointer Assignment’ mean and what causes this error?
34. What is near, far and huge pointers? How many bytes are occupied by them?
35. How would you obtain segment and offset addresses from a far address of a memory
location?
36. Are the expressions arr and *arr same for an array of integers?
37. Does mentioning the array name gives the base address in all the contexts?
38. Explain one method to process an entire string as one unit?
39. What is the similarity between a Structure, Union and enumeration?
40. Can a Structure contain a Pointer to itself?
41. How can we check whether the contents of two structure variables are same or not?
42. How are Structure passing and returning implemented by the complier?
43. How can we read/write Structures from/to data files?
44. What is the difference between an enumeration and a set of pre-processor # defines?
45. What do the ‘c’ and ‘v’ in argc and argv stand for?
46. Are the variables argc and argv are local to main?
47. What is the maximum combined length of command line arguments including the space
between adjacent arguments?
48. 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?
49. Does there exist any way to make the command line arguments available to other
functions without passing them as arguments to the function?
50. What are bit fields? What is the use of bit fields in a Structure declaration?
51. To which numbering system can the binary number 1101100100111100 be easily
converted to?
52. Which bit wise operator is suitable for checking whether a particular bit is on or off?
53. Which bit wise operator is suitable for turning off a particular bit in a number?
54. Which bit wise operator is suitable for putting on a particular bit in a number?
55. Which bit wise operator is suitable for checking whether a particular bit is on or off?
56. Which one is equivalent to multiplying by 2?
o Left shifting a number by 1
o Left shifting an unsigned int or char by 1?
57. Write a program to compare two strings without using the strcmp() function.
58. Write a program to concatenate two strings.
59. Write a program to interchange 2 variables without using the third one.
60. Write programs for String Reversal. The same for Palindrome check.
61. Write a program to find the Factorial of a number.
62. Write a program to generate the Fibonacci Series?
63. Write a program which employs Recursion?
64. Write a program which uses command line arguments.
65. Write a program which uses functions like strcmp(), strcpy(), etc.
66. What are the advantages of using typedef in a program?
67. How would you dynamically allocate a one-dimensional and two-dimensional array of
integers?
68. How can you increase the size of a dynamically allocated array?
69. How can you increase the size of a statically allocated array?
70. 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?
71. Which function should be used to free the memory allocated by calloc()?
72. How much maximum can you allocate in a single call to malloc()?
73. Can you dynamically allocate arrays in expanded memory?
74. What is object file? How can you access object file?
75. Which header file should you include if you are to develop a function which can accept
variable number of arguments?
76. Can you write a function similar to printf()?
77. How can a called function determine the number of arguments that have been passed to
it?
78. Can there be at least some solution to determine the number of arguments passed to a
variable argument list function?
79. How do you declare the following:
o An array of three pointers to chars
o An array of three char pointers
o A pointer to array of three chars
o A pointer to function which receives an int pointer and returns a float pointer
o A pointer to a function which receives nothing and returns nothing
80. What do the functions atoi(), itoa() and gcvt() do?
81. Does there exist any other function which can be used to convert an integer or a float to a
string?
82. How would you use qsort() function to sort an array of structures?
83. How would you use qsort() function to sort the name stored in an array of pointers to
string?
84. How would you use bsearch() function to search a name stored in array of pointers to
string?
85. How would you use the functions sin(), pow(), sqrt()?
86. How would you use the functions memcpy(), memset(), memmove()?
87. How would you use the functions fseek(), freed(), fwrite() and ftell()?
88. How would you obtain the current time and difference between two times?
89. How would you use the functions randomize() and random()?
90. How would you implement a substr() function that extracts a sub string from a given
string?
91. What is the difference between the functions rand(), random(), srand() and randomize()?
92. What is the difference between the functions memmove() and memcpy()?
93. How do you print a string on the printer?
94. Can you use the function fprintf() to display the output on the screen?
95. Gautam Pagedar adds this question: What is a linklist and why do we use it when we
have arrays? - I feel the correct answer should be linklist is used in cases where you donÃ
¢â‚¬â„¢t know the memory required to store a data structure and need to allocate is
dynamically on demand.
96. How do you detect a loop in linked list?
97. Sunil asks: What is the difference between main() in C and main() in C++?
98. ajz at his interviews asks what will be printed out when the following code is executed:

main()
{
printf("%x",-1<<4);
}

You might also like