edited by
697 views
9 votes
9 votes

Consider the following C Code

#include<stdio.h>
int main()
{
   int i=0;
   do
   {
       do
       {

          while(i++<2);

       }while(i++<4);

   }while(i++<=9);

   printf("%d",i++);

   return 0;
}
   


What will be the output of the above program?

  1. $13$
  2. $11$
  3. $12$
  4. $10$
edited by

1 Answer

Best answer
19 votes
19 votes

We can do that, in this way.

  • $i = 0<2\; \checkmark$
  • $i = 1<2\; \checkmark$
  • $i = 2<2$
  • $i = 3<4\; \checkmark$
  • $i = 4<2$
  • $i = 5<4$
  • $i = 6\leq 9\; \checkmark$
  • $i = 7<2$
  • $i = 8<4$
  • $i = 9\leq 9\; \checkmark$
  • $i = 10<2$
  • $i = 11<4$
  • $i = 12\leq 9$
  • $ i = 13$
printf("%d",i++);

$\therefore i = 13$ is printed, and at last $i = 14.$

So, the correct answer is $(A).$

selected by
Answer:

Related questions

8 votes
8 votes
1 answer
1
gatecse asked Jan 17, 2021
374 views
What will be the output?#include<stdio.h int g; int main() { static int a,b; int c=2,d; d = (a||(++b &&(c | ++g))); printf("%d",d); }$0$$3$$1$Garbage value