1(a)
|
What is the difference between call by value and call reference with
respect to memory allocation? Give a suitable example to illustrate using C++
code.
|
2
|
Ans
|
Call by value: The formal parameter and the actual parameter to
occupy separate memory locations and hence the changes in formal parameter
does not affect the value of actual parameters.
Call by reference: The formal parameter and the actual parameter
occupy same memory locations and hence the changes in formal parameter get
reflected in the value of actual parameters.
void Calculate(int A, int & B)//A is call by value
{
//B is call by reference
A++;
B+=A;
}
OR
void Calculate(int A, int &B);
// A is call by value,
// B is call by reference.
|
|
(b)
|
Observe the following C++ code and write the name(s) of the header
files(s), which will be essentially required to run it in a C++ compiler:
void main()
{
char CH, STR[20];
cin>>STR;
CH=toupper(STR[0]);
cout<<STR<<”
starts with”<<CH<<endl;
}
|
1
|
Ans
|
iostream.h OR iomanip.h
ctype.h
|
|
(c)
|
Rewrite the following C++ code after removing all the syntax
error(s), if present in the code. Make sure that you underline each
correction done by you in the code.
Important Note:
Assuming that all the
required header files are already included which are
essential to run this
code.
The corrections made by
you do not change the logic of the program.
typedef char[80] STR;
void main()
{
Txt STR;
gets(Txt);
cout<<Txt[0]<<’\t’<<Txt[2];
cout<<Txt<<endline;
}
|
2
|
Ans
|
typedef char STR[80];
//Error 1
void main()
{
STR Txt; //Error 2
gets(Txt);
cout<<Txt[0]<<’\t’<<Txt[2]; //OR
“\t” Error 3
cout<<Txt<<endl; //
Error 4
}
|
|
(f)
|
Read the following C++ code carefully and find out, which out of the
given options
(i) to (iv)
are the expected correct output(s) of it. Also, write the maximum and minimum value
that can be assigned to the variable Taker used in the code:
void main()
{
Int
GuessMe[4]={100,50,200,20};
Int Taker=random(2)+2;
for(int chance=0;
chance<Taker; chance++)
cout<<GuessMe[chance]<<”#”;
}
(i) 100#
(ii) 50#200#
(iii) 100#50#200#
(iv) 100#50
|
2
|
Ans
|
(iii) 100#50#200#
Min value of Taker=2
Max value of Taker=3
|
Thursday, 25 February 2016
11th & 12th CS 2014(Outside Delhi) COMMON ASSIGNMENT
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment