1.
What will be the output of following?
Options:
A. 6
B. 5
C. Garbage Value
D. Compiler Error
Answer : D
Explanation : It will give compile time error because we are trying to change the constant value. p is a pointer to a "constant integer". But we tried to change the value of the "constant integer".
2.
What will be the output of following?
Options:
A. 1 1
B. 1 8
C. 2 1
D. 2 2
Answer : B
Explanation : The sizeof() operator gives the number of bytes taken by its operand. P is a character pointer, which needs one byte for storing its value (a character). Hence sizeof(*p) gives a value of 1. Since it needs two bytes to store the address of the character pointer sizeof(p) gives 8.
3.
What will be the output of following?
Options:
A. 1 1 2 3
B. 1 1 2 2
C. 0 1 2 2
D. 0 1 2 3
Answer : B
Explanation : In an expression involving || operator, evaluation takes place from left to right and will be stopped if one of its components evaluates to true(a non zero value).
So in the given expression m = i++ || j++ || k++.
It will be stop at j and assign the current value of j in m.
therefore m = 1, i = 1, j = 2 and k = 2 (since k++ will not encounter. so its value remain 2)
4.
What will be the output of following?
Options:
A. 0 1
B. 1 0
C. 0 0
D. 1 1
Answer : B
Explanation : Since the evaluation is from right to left. So when the print statement execute value of i = 0, as its executing from right to left - when i++ will be execute first and print value 0 (since its post increment ) and after printing 0 value of i become 1.
5.
What will be the output of following?