InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
What is the order of objects destroyed in the memory? |
|
Answer» The objects are destroyed in the reverse order of their creation. |
|
| 2. |
What is a virtual destructor? |
|
Answer» A virtual destructor ensures that the objects resources are released in the reverse order of the object being constructed w.r.t inherited object. |
|
| 3. |
Can we nest multi line comments in a C++ code? |
|
Answer» No, we cannot. |
|
| 4. |
What is the purpose of #undef preprocessor? |
|
Answer» It will be used to undefine an existing macro definition. |
|
| 5. |
Is 068 a valid octal number? |
|
Answer» No, it contains invalid octal digits. |
|
| 6. |
S++ or S = S+1, which can be recommended to increment the value by 1 and why? |
|
Answer» S++, as it is single machine instruction (INC) internally. |
|
| 7. |
What is difference between including the header file with-in angular braces < > and double quotes “ “ |
|
Answer» If a header file is included with in < > then the compiler searches for the particular header file only with in the built in include path. If a header file is included with in “ “, then the compiler searches for the particular header file first in the current working directory, if not found then in the built in include path |
|
| 8. |
If a pointer declared for a class, which operator can be used to access its class members? |
|
Answer» Arrow (->) operator can be used for the same |
|
| 9. |
What is the use of the keyword ‘using’? |
|
Answer» It is used to specify the namespace being used in. |
|
| 10. |
What is ‘cin’? |
|
Answer» cin is the object of istream class. The stream ‘cin’ is by default connected to console input device. |
|
| 11. |
What is ‘cout’? |
|
Answer» cout is the object of ostream class. The stream ‘cout’ is by default connected to console output device. |
|
| 12. |
What is the full form of STL? |
|
Answer» Standard template library |
|
| 13. |
What is ‘std’? |
|
Answer» Default namespace defined by C++. |
|
| 14. |
Can we create and empty class? If so what would be the size of such object. |
|
Answer» We can create an empty class and the object size will be 1. |
|
| 15. |
Are class functions taken into consideration as part of the object size? |
|
Answer» No, only the class member variables determines the size of the respective class object. |
|
| 16. |
Which function is used to move the stream pointer for the purpose of writing data from stream? |
|
Answer» seekp() |
|
| 17. |
Which function is used to move the stream pointer for the purpose of reading data from stream? |
|
Answer» seekg() |
|
| 18. |
Are the exceptions and error same? |
|
Answer» No, exceptions can be handled whereas program cannot resolve errors. |
|
| 19. |
What happens if an exception is thrown outside a try block? |
|
Answer» The program shall quit abruptly. |
|
| 20. |
Is it legal to assign a base class object to a derived class pointer? |
|
Answer» No, it will be error as the compiler fails to do conversion. |
|
| 21. |
Does an abstract class in C++ need to hold all pure virtual functions? |
|
Answer» Not necessarily, a class having at least one pure virtual function is abstract class too. |
|
| 22. |
What is the difference between delete and delete[]? |
|
Answer» Delete[] is used to release the array allocated memory which was allocated using new[] and delete is used to release one chunk of memory which was allocated using new. |
|
| 23. |
What are available mode of inheritance to inherit one class from another? |
|
Answer» Public, private & protected |
|
| 24. |
What is the default function call method? |
|
Answer» By default the functions are called by value. |
|
| 25. |
What is the maximum length of an identifier? |
|
Answer» Ideally it is 32 characters and also implementation dependent. |
|
| 26. |
What is the first string in the argument vector w.r.t command line arguments? |
|
Answer» Program name. |
|
| 27. |
What is recursion? |
|
Answer» Function calling itself is called as recursion. |
|
| 28. |
What are valid operations on pointers? |
|
Answer» The only two permitted operations on pointers are
|
|
| 29. |
How can we refer to the global variable if the local and the global variable names are same? |
|
Answer» We can apply scope resolution operator (::) to the for the scope of global variable. |
|
| 30. |
Which operator can be used to determine the size of a data type/class or variable/object? |
|
Answer» sizeof |
|
| 31. |
Who designed C++ programming language? |
|
Answer» Bjarne Stroustrup. |
|
| 32. |
Can we resize the allocated memory which was allocated using ‘new’ operator? |
|
Answer» No, there is no such provision available. |
|
| 33. |
Which compiler switch to be used for compiling the programs using math library with g++ compiler? |
|
Answer» Opiton –lm to be used as > g++ –lm <file.cpp> |
|
| 34. |
What is reminder for 5.0 % 2? |
|
Answer» Error, It is invalid that either of the operands for the modulus operator (%) is a real number. |
|
| 35. |
What are the different ways of passing parameters to the functions? Which to use when? |
Answer»
|
|
| 36. |
What is a container class? |
|
Answer» A class containing at least one member variable of another class type in it is called so. |
|
| 37. |
Where an automatic variable is stored? |
|
Answer» Every local variable by default being an auto variable is stored in stack memory |
|
| 38. |
Can a program be compiled without main() function? |
|
Answer» Yes, it can be but cannot be executed, as the execution requires main() function definition. |
|
| 39. |
What is the meaning of base address of the array? |
|
Answer» The starting address of the array is called as the base address of the array. |
|
| 40. |
What is the purpose of extern storage specifier. |
|
Answer» Used to resolve the scope of global symbol #include <iostream>using namespace std;main() { extern int i; cout<<i<<endl;}int i = 20;
|
|
| 41. |
What is a static variable? |
|
Answer» A static local variables retains its value between the function call and the default value is 0. The following function will print 1 2 3 if called thrice. void f() { static int i; ++i; printf(“%d “,i); }If a global variable is static then its visibility is limited to the same source code. |
|
| 42. |
What is keyword auto for? |
|
Answer» By default every local variable of the function is automatic (auto). In the below function both the variables ‘i’ and ‘j’ are automatic variables. void f() { int i; auto int j;}NOTE − A global variable can’t be an automatic variable. |
|
| 43. |
How can we catch all kind of exceptions in a single catch block? |
|
Answer» The catch block with ellipses as follows catch(…) {}
|
|
| 44. |
What is a class template? |
|
Answer» A template class is a generic class. The keyword template can be used to define a class template. |
|
| 45. |
What are command line arguments? |
|
Answer» The arguments/parameters which are sent to the main() function while executing from the command line/console are called so. All the arguments sent are the strings only. |
|
| 46. |
What is a namespace? |
|
Answer» A namespace is the logical division of the code which can be used to resolve the name conflict of the identifiers by placing them under different name space. |
|
| 47. |
What is the role of the file opening mode ios::trunk? |
|
Answer» If the file already exists, its content will be truncated before opening the file. |
|
| 48. |
What is the block scope variable in C++? |
|
Answer» A variable whose scope is applicable only within a block is said so. Also a variable in C++ can be declared anywhere within the block. |
|
| 49. |
Can we implement all the concepts of OOPS using the keyword struct? |
|
Answer» Yes. |
|
| 50. |
What is the difference between the keywords struct and class in C++? |
|
Answer» By default the members of struct are public and by default the members of the class are private. |
|