Important Questions

CBSE Guess > Papers > Important Questions > Class XII > 2010 > Computer Science > Computer Science By MRK

CBSE CLASS XII

2005 Delhi

1.a. Differentiate between a Call by Value and Call by Reference, giving suitable examples of each.

Ans. Call by value: In call by value method, the called function creates a new set of variables and copies the values of arguments into them. The function does not have access to the original variables (actual parameters) and can only work on the copies of values it created. Passing arguments by value is useful when the original values are not to be modified.
In call by reference method, a reference to the actual argument (original variable) is passed to the called function. (Reference is an alias for a predefined variable. Ie the same variable value can be accessed by any of the two names: the original variable’s name and the reference name.) Thus, in call by reference method, the changes are reflected back to the original values. The call by reference method is useful in situations where the values of the original variables are to be changed using a function.
Program to illustrate the call by value method of function invoking:
#include<iostream.h>
#include<conio.h>
int change(int);
void main( )
{ clrscr( );
int orig=10;
cout<<”\nThe original value
is”<<orig<<”\n”;
cout<<”\nReturn value of function
change()is “<<change(orig)<<”\n”;
cout<<”\nThe value after function change() is
over”<<orig<<”\n;
getch();
}
int change(int duplicate)
{ duplicate=20;
return duplicate;
}

Ans. Output:
The original value is 10
Return value of function change() is 20
The value after function change() is over 10
Program to illustrate the call by Reference method of function invoking:
#include<iostream.h>
#include<conio.h>
int change(int&);
void main( )
{ clrscr( );
int orig=10;
cout<<”\nThe original value
is”<<orig<<”\n”;
cout<<”\nReturn value of function
change()is “<<change(orig)<<”\n”;
cout<<”\nThe value after function change() is
over”<<orig<<”\n;
getch();
}
int change(int &duplicate)
{ duplicate=20;
return duplicate;
}

Output.
The original value is 10
Return value of function change() is 20
The value after function change() is over 20

1. b. Name the header files to which the following belong: 1
(i) abs( ) (ii) strcmp( )

Ans. (i) abs( ) - stdlib.h, math.h, complex.h
(ii) strcmp( ) - string.h

Paper By Mr. MRK
Email Id : [email protected]@yahoo.com