recategorized by
1,320 views
1 votes
1 votes

The output of the program code

main()
{
int x=0;
while (x<=10)
for(;;)
if(++x%10==0)
break;
printf(“x=%d”,x);
}

is :

  1. x=1                
  2. compilation error
  3. x=20                       
  4. none of the above
recategorized by

2 Answers

2 votes
2 votes

The Answer is C). X=20

When While loop enters for the first time, x=0. So, It enters the loop. Then there is infinite for loop where it breaks when x becomes multiples of 10.

When ++x becomes 10, then 10%10==0 → True, so, it breaks the for loop

After that, It goes again into while loop, where it checks condition for x<=10 and it gets satisfied as x=10 now. So, The For loop again iterates for 10 times till x becomes 20. When X=20, It breaks the for loop. Now, The while condition is checked x>10. Condition fails.

Finally, It prints X=20

1 votes
1 votes

(D) none of the above

it will be print 9

Related questions

1 votes
1 votes
1 answer
2
0 votes
0 votes
0 answers
3
0 votes
0 votes
0 answers
4