Algorithms Quiz | SP2 Contest 1 | Question 4
What will be the output of the below C program?
#include <stdio.h> int main() { int x = 2; do { ++x; printf ( "%d" , x); } while (--x <= 2); return 0; } |
(A) Runtime Error
(B) 2
(C) 3
(D) Infinite Loop
Answer: (D)
Explanation: As the value of x is incremented(++x) and then decremented(–x), hence no change in the value of x will occur and it will be as 2.
Quiz of this Question
Please comment below if you find anything wrong in the above post
Please Login to comment...