1. What will be the output of following?
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?
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?
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?
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?
Answer : C
Explanation : x[i] is equivalent to *(x + i), so (buf + 1) is *(buf + 1 + 5), or buf.
This article is contributed by Rishabh Jain. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.