What is output of below program?int main(){int i,j,count;count=0;for(i=0; i<5; i++);{for(j=0;j<5;j++);{ count++;}}printf("%d",count);return 0;} (A) 55(B) 54(C) 0(D) 1
Question
What is output of below program?int main(){int i,j,count;count=0;for(i=0; i<5; i++);{for(j=0;j<5;j++);{ count++;}}printf("%d",count);return 0;} (A) 55(B) 54(C) 0(D) 1
Solution
The output of the program will be 1 (Option D).
Here's the step by step explanation:
-
The program starts with the main function where three integer variables i, j, and count are declared. The variable count is initialized to 0.
-
Then there are two nested for loops. The outer loop runs from i=0 to i<5 and the inner loop runs from j=0 to j<5. However, due to the semicolon (;) at the end of both for loop statements, the loops do not contain any statements to execute. So, they just iterate without affecting any variables or performing any operations.
-
After the loops, the statement count++ is executed only once because it is not inside the loop blocks (due to the semicolons at the end of the for statements). This increments the value of count from 0 to 1.
-
Finally, the value of count (which is 1) is printed and the program returns 0, indicating successful execution.
So, the output of the program is 1.
Similar Questions
What is the output of the following code?#include <stdio.h>int main() { for (int i = 0; i < 5; i++) { for (int j = 5; j > 0; j--) { if (i > j) continue; printf("%d%d ", i, j); } printf("\n"); } return 0;}
What is the output of the following code:void main(){int i;for(i=65;i<70;i++) printf(“%c,”,i);}a.65,66,67,68,69,70b.a,b,c,d,e,c.A,B,C,D,E,d.A,B,C,D,E
What will be the output of the following C program?#include<stdio.h>int main(){ int a[5] = {5, 3, 15, 20, 25}; int i, j, m; i = ++a[1]; j = a[1]++; m = a[i++]; printf("%d, %d, %d", i, j, m); return 0;}
What will be the output of the following C code? #include void main() { int a[2][3] = {1, 2, 3, 4, 5}; int i = 0, j = 0; for (i = 0; i < 2; i++) for (j = 0; j < 3; j++) printf("%d", a[i][j]); }a.1 2 3 4 5 0b.1 2 3 4 5 junkc.1 2 3 4 5 5d.Run time error
What is the output of the code given below?#include <stdio.h> void main() { int i; for (i = 5; i < 10; i++); printf("%d ", i);}Options5105 6 7 8 99
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.