Академический Документы
Профессиональный Документы
Культура Документы
Answer : When two operands of different data types are encountered in the same expression, the
variable of lower data type is automatically converted to the data types of variable with higher
data type, and then the expression is calculated.
Q4: What is the difference between call by value and call by reference in user defined
functions in C++?
Answer : The value of the actual parameters in the calling function do not get affected when the
arguments are passed using call by value method, since actual and formal parameters have
different memory locations. The values of the formal parameters affect the values of actual
parameters in the calling function, when the arguments are passed using call by reference
method. This happens since the formal parameters are not allocated any memory, but they refer
to the memory locations of their corresponding actual parameter. When the function needs to
return more than one value to the calling function, it may be achieved through call by reference.
Also during passing of objects to the functions, when the size of the object is large, passing by
reference reduces the time required for copying individual members to the formal argument.
Q9: What are the different categories of variables? Discuss about them briefly.
Answer: Automatic or Local variables, External or Global variables, Static Local variables.
Automatic variables are not created until the function or block in which they are defined is
called and they are destroyed when the control return from that function or comes out that block.
They are visible (accessible) only within that function. Value is not initialized automatically.
Global variables are visible (accessible) to all the functions in that program. They are initialized
to 0 automatically. They exist for entire lifetime of the program.
Static local variables have visibility same as automatic variables but have lifetime same as
global variables. Initialization takes place only once at the first time the function is called.
Q12: What are the major differences between Object Oriented Programming and
Procedural Programming?
Answer :
Object Oriented Programming
*Emphasis on data
*Follow bottom up approach in program design
*Concept of Data hiding prevents accidental change in the data
*Polymorphism, inheritance, Data Encapsulation possible
Procedural Programming
*Emphasis on doing things (function)
*Follow top-down approach in program design
*Due to presence of global variables, there are possibilities of accidental change in data
Q17:What is class?
Answer : A class can be declared as a collection of data members along with members function
which allows association of data and functions into a single unit called encapsulation.
Eg. Class A
{ private:
static int a;
public:
…………;
…………;
};
int A::a = 0;
…….