C++ sample Exams with their answers
Part ፩ : Choose the best answer from the following alternativealternatives.(1.5 each)
1. Evaluate the following !(1 && !(0 || 1))
A. 0 B. 1 C. -1 D. error
2. How many times will the following while loop print "hello"?
....
int main()
int i=1;
while(i<=10){
cout<<"hello world";}
return 0;}
A. 10 B. 8 C. An infinite number of times D. none
3. Which one is not Mandatory part in function declaration?
A. return type B. parameters C. function name D. none
4. the following loops is supposed to print all even numbers from 0 to 20 which option will be replaced for the blank space?
.....
k=0;
while(k<=20 {
cout<
A. k=2*k B. k=k+1 C. k=k+2 D. k=k-2
5. Given program as follows , what would be printed?
int myFun(int n) {
if(n==0)
return 0;
else
return n+ myFun(n-1);}
A. 0 B. 10 C. 5 D. 15
6. Assume x=4,y=6; what will be the output of the fololwing code? if(x<5)
if(y<5)
cout<<"welcome to BDU";
else
cout<<"Hello students";
A. Welcome to BDU B. Hello students C. Welcome to BDU Hello students D. No Output 7.What will be the output of the following code?
void f(int &i)
{
i=1*5;
}
int main()
{
int n = 5;
f(n);
cout <
8. What will be the output the following code when you enter the n value 5?
int main ()
{
int n,i;
cout<<"Enter the n value";
cin>>n;
for (i-1; i
if(i == 3)
break;
return 0;
}
A. 2 3 4 5
B. 3 4 5
C. 1 2 3
D. 2 3
9. Which one of the following function calling method copies the value of an argument into
the formal parameter of the function?
A. Call by reference
B. Call by value
C. Call by pointer
D. None
10. Where is the scope of a variable declared in the user defined function?
A. Inside main function
B. Only inside the function {} block
C. Everywhere in a program
D. Both a and b
11. Where does the default parameter appear in a function parameter list?
A. Leftmost
B. Rightmost
C. Middle
D. Both a and b
12. What will happen while using pass by reference?
A. After the function call the value of referenced memory location will be affected
B. The location of variable in a memory is passed to the function, so that it can use
the same memory area for its processing
C. The function declaration should contain ampersand (& in its type declaration)
D. All of the mentioned
what about the answer of #Q3?
ReplyDeleteB) parameter is the correct answer it is not mandatory for function declaration
Delete