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

Test PDF

Uploaded by

Manu Kaul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
54 views

Test PDF

Uploaded by

Manu Kaul
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Q1.

int main()
{
int main = 3;
printf("%d", main);
return 0;
}
Which of the following is true?
(a) It will cause a compile-time error
(c) It will run without any error and prints 3

(b) It will cause a run-time error


(d) It will experience infinite looping

Answer: c

Q2.
int i=5, j=6,z;
printf("%d", i+++j);
What is the output?
(a) 11
(c) 10

(b) It will cause a compile-time error


(d) 12

Answer: a
Explanation: Treat it as i++ + j

Q3.

What happens if the program below is executed?

int X(int *a, int *b){


*a = *a + *b;
*b = *a - *b;
*a = *a - *b;
}
int main(void) {
int x=10,y=20;
X(&x,&y);
printf("x = %d, y = %d\n", x,y);
1

return 0;
}
(a) Compile-Error
(c) x = 20, y = 10

(b) x = 10, y = -20


(d) x = -10, y = -20

Answer: c
Explanation: Swaps values

Q4.

What happens if the program below is executed?

int main()
{
int a[5] = {5, 1, 15, 20, 25};
int i, j, m;
i = ++a[1];
j = a[1]++;
m = a[i++];
printf("%d, %d, %d", i, j, m);
return 0;
}
(a) 2, 3, 4
(c) 4, 6, 15

(b) 3, 2, 15
(d) 2, 4, 8

Answer: b

Q5.

What happens if the program below is executed?

int const *p = 5;
printf("%d", ++(*p));
What is the output?
(a) Error (b) 5
(c) 6
(d) 7
Answer: a

Q6.

What is the following algorithm computing?

1. Pick an arbitrary positive integer S > 0 and x0 = S/2




2. xn+1 = 12 xn + xSn
2

3. Keep repeating step 2 until convergence


(a)
Approximate Arithmetic Mean
(c) S

(b) Approximate Geometric Mean


(d) S 2

Answer: c (Herons Method to compute square root iteratively)

Q7. What will be the result of the expression 13 & 25?


(a) 38 (b) 25
(c) 9
(d) 12
Answer: c 9

Q8.

Which of the statements are true ?

I. Function overloading is done at compile time.


II. Protected members are accessible to the member of derived class.
III. A derived class inherits constructors and destructors.
IV. A friend function can be called like a normal function.
V. Nested class is a derived class.
(a) I, II, III
(c) III, IV, V

(b) II, III, V


(d) I, II, IV

Answer: d

Q9. A struct is the same as a class except that


(a) There are no member functions
(b) All members are public
(c) Cannot be used in inheritance hierarchy (d) It does have a this pointer
Answer: c

Q10. If x = 5, y = 2 then x y equals ?.


(where is a bitwise XOR operator)
(a) 00000111
(c) 10100000

(b) 10000010
(d) 11001000

Answer: a

You might also like