Skip to content
Related Articles

Related Articles

Improve Article
Algorithms Quiz | SP2 Contest 1 | Question 4
  • Last Updated : 28 Aug, 2018

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

My Personal Notes arrow_drop_up
Recommended Articles
Page :