Open In App

Algorithms Quiz | SP2 Contest 1 | Question 4

Like Article
Like
Save
Share
Report

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


Last Updated : 28 Aug, 2018
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads