0% found this document useful (0 votes)
21 views

All Questions Are Compulsory: (Time Allowed: 3hours) (Maximum Marks:70) (I) (Ii) Programming Language: C++

This document contains the questions and answers from a 2009 CBSE Board Computer Science exam. The first question asks about the difference between call by value and call by reference in C++ and provides examples to illustrate each. The second question asks the header files that puts() and sin() belong to. The third question asks to rewrite a C++ program that contains syntactical errors, underlining the corrections made. The program defines an Employee class with member variables and methods to join and list employee details.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

All Questions Are Compulsory: (Time Allowed: 3hours) (Maximum Marks:70) (I) (Ii) Programming Language: C++

This document contains the questions and answers from a 2009 CBSE Board Computer Science exam. The first question asks about the difference between call by value and call by reference in C++ and provides examples to illustrate each. The second question asks the header files that puts() and sin() belong to. The third question asks to rewrite a C++ program that contains syntactical errors, underlining the corrections made. The program defines an Employee class with member variables and methods to join and list employee details.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

XII COMPUTER SCIENCE

CBSE Board - 2009

[Time allowed: 3hours]


Instructions (i)
All questions are compulsory
(ii)
Programming Language: C++
1.
(a)
Ans

[Maximum Marks :70]

What is the difference between call by value and call by reference? Give an example
in C++ to illustrate both.
Call By Value
Call by value is used to create a
temporary copy of the data which is
transferred from the actual
parameter in the final parameter.
The changes done in the function in
formal parameter are not reflected
back in the calling environment.
It does not use & sign
Example:
#include <iostream.h>
void change(int x, int y)
{
x = 10; /* change the value
of x */
y = 20; /* change the value
of y */
}
void change(int x, int y);
void main ()
{
// local variable
declaration:
int a = 100;
int b = 200;
cout <<
value of a
cout <<
value of b

"Before
:" << a
"Before
:" << b

change,
<< endl;
change,
<< endl;

change(a, b);
cout
of a :"
cout
of b :"

<<
<<
<<
<<

"After change, value


a << endl;
"After change, value
b << endl;

Call by reference
Call by reference is used to share
the same memory location for
actual and formal parameters
The changes done in the function
are reflected back in the calling
environment.
It makes the use of the & sign as
the reference operator. Example
#include <iostream.h>
void change(int *x, int *y)
{
*x = 10; /* change the
value
of x */
*y = 20; /* change the
value
of y */
}
void change(int *x, int *y);
void main ()
{
// local variable
declaration:
int a = 100;
int b = 200;
cout <<
value of a
cout <<
value of b

"Before
:" << a
"Before
:" << b

change,
<< endl;
change,
<< endl;

change(&a, &b);
cout << "After change,
value of a :" << a << endl;

}
Value of a and b did not
changed after over writing the
value of x and y which contain
the value of a and b.

(b)
Ans
(c)

Ans

cout <<
value of b
}
Value of a
after over
of x and y
value of a

"After change,
:" << b << endl;
and b is changed
writing the value
which contain the
and b.

Write the names of the header files to which the following belong:
(i) puts( )
(ii) sin( )
(i)
stdio.h
(ii)
math.h
Rewrite the following program after removing the syntactical error(s) (if any).
Underline each correction.
#include [iostream.h]
#include [stdio.h]
class Employee
{
int EmpId=901; char EName[20];
public
Employee( ) { }
void Joinint( ) { cin>>EmpId; gets(EName); }
void List( ) { cout<<EmpId<<:<<EName<<endl;}
};
void main( )
{
Employee E; Joining.E( ); E.List( )
}
#include <iostream.h>
#include <stdio.h>
class Employee
{
int EmpId;
char EName[20];
public:
Employee( )
{}

You might also like