What will be the output of the following C code?#include <stdio.h>main( ){int i;for (i=0; i<5; i++){int i = 10;printf("%d", i);i++;}return 0;}

By K Balaji|Updated : September 27th, 2022
  1. 10 11 12 13 14
  2. 10 10 10 10 10
  3. 0 1 2 3 4
  4. Compilation error

The output of the following C code #include <stdio.h>main( ){int i;for (i=0; i<5; i++){int i = 10;printf("%d", i);i++;}return 0;} is 10 10 10 10 10.

#include <stdio.h>

main( )

{

int i;

for ( i=0; i<5; i++ ) //this loop runs 5 times

{

int i = 10;// initialised to 10

printf("%d", i); // It prints 10

i++;// incremented by 1 but here i is a local variable inside a for loop.[this i values are 0,1,2,3,4]

}

return 0;

}

Output will be 10 10 10 10 10

Summary:-

What will be the output of the following C code?#include <stdio.h>main( ){int i;for (i=0; i<5; i++){int i = 10;printf("%d", i);i++;}return 0;} 10 11 12 13 14, 10 10 10 10 10, 0 1 2 3 4, Compilation error

The output of #include <stdio.h>main( ){int i;for (i=0; i<5; i++){int i = 10;printf("%d", i);i++;}return 0;} is 10 10 10 10 10

Related Questions:-

Comments

write a comment

Follow us for latest updates