Академический Документы
Профессиональный Документы
Культура Документы
delete operator is used to release the dynamic memory which was created using
new operator.
Can I use malloc() function of C language to allocate dynamic memory in C++?
Yes, as C is the subset of C++, we can all the functions of C in C++ too.
Can I use delete operator to release the memory which was allocated using
malloc() function of C language?
No, we need to use free() of C language for the same.
What is a friend function?
A function which is not a member of the class but still can access all the member of
the class is called so. To make it happen we need to declare within the required
class following the keyword friend.
What is a copy constructor?
A copy constructor is the constructor which take same class object reference as the
parameter. It gets automatically invoked as soon as the object is initialized with
another object of the same class at the time of its creation.
Does C++ supports exception handling? If so what are the keywords involved in
achieving the same.
C++ does supports exception handling. try, catch & throw are keyword used for the
same.
Explain the pointer this.
This, is the pointer variable of the compiler which always holds the current active
objects address.
What is the difference between the keywords struct and class in C++?
By default the members of struct are public and by default the members of the
class are private.
Can we implement all the concepts of OOPS using the keyword struct?
Yes.
What is the block scope variable in C++?
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.
What is the role of the file opening mode ios::trunk?
If the file already exists, its content will be truncated before opening the file.
What is the scope resolution operator?
The scope resolution operator is used to
Resolve the scope of global variables.
To associate function definition to a class if the function is defined outside
the class.
What is a namespace?
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.
What are command line arguments?
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.
What is a class template?
A template class is a generic class. The keyword template can be used to define a
class template.
How can we catch all kind of exceptions in a single catch block?
The catch block with ellipses as follows
catch()
{
}
What is keyword auto for?
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 cant be an automatic variable.
What is a static variable?
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.
What is the purpose of extern storage specifier.
Used to resolve the scope of global symbol
#include <iostream>
cout<<i<<endl;
}
int i=20;
What is the meaning of base address of the array?
The starting address of the array is called as the base address of the array.
When should we use the register storage specifier?
If a variable is used most frequently then it should be declared using register
storage specifier, then possibly the compiler gives CPU register for its storage to
speed up the look up of the variable.
Can a program be compiled without main() function?
Yes, it can be but cannot be executed, as the execution requires main() function
definition.
Where an automatic variable is stored?
Every local variable by default being an auto variable is stored in stack memory
What is a container class?
A class containing at least one member variable of another class type in it is called
so.
sizeof
How can we refer to the global variable if the local and the global variable names
are same?
We can apply scope resolution operator (::) to the for the scope of global variable.
What are valid operations on pointers?
The only two permitted operations on pointers are
Comparision ii) Addition/Substraction (excluding void pointers)
What is recursion?
Function calling itself is called as recursion.
What is the first string in the argument vector w.r.t command line arguments?
Program name.
What is the maximum length of an identifier?
Ideally it is 32 characters and also implementation dependent.
What is the default function call method?
By default the functions are called by value.
What are available mode of inheritance to inherit one class from another?
Public, private & protected
What is the difference between delete and delete[]?
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.
Does an abstract class in C++ need to hold all pure virtual functions?
Not necessarily, a class having at least one pure virtual function is abstract class
too.
What is cout?
cout is the object of ostream class. The stream cout is by default connected to
console output device.
What is cin?
cin is the object of istream class. The stream cin is by default connected to
console input device.
What is the use of the keyword using?
It is used to specify the namespace being used in.
If a pointer declared for a class, which operator can be used to access its class
members?
Arrow (->) operator can be used for the same
What is difference between including the header file with-in angular braces < >
and double quotes
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
S++ or S=S+1, which can be recommended to increment the value by 1 and why?
S++, as it is single machine instruction (INC) internally.
What is the difference between actual and formal parameters?
The parameters sent to the function at calling end are called as actual parameters
while at the receiving of the function definition called as formal parameters.
What is the difference between variable declaration and variable definition?
Declaration associates type to the variable whereas definition gives the value to the
variable.
Which key word is used to perform unconditional branching?
goto.
Is 068 a valid octal number?
No, it contains invalid octal digits.
What is the purpose of #undef preprocessor?
It will be used to undefine an existing macro definition.
Can we nest multi line comments in a C++ code?
No, we cannot.
What is a virtual destructor?
A virtual destructor ensures that the objects resources are released in the reverse
order of the object being constructed w.r.t inherited object.
What is the order of objects destroyed in the memory?
The objects are destroyed in the reverse order of their creation.
What is a friend class?
A class members can gain accessibility over other class member by placing the
class declaration prefixed with the keyword friend in the destination class.