WorksheetsLearn2Code-17-09-2025
Total questions: 30
Worksheet time: 15mins
What is the output of the following program?
#include <stdio.h>
int main() {
int i;
for (i = 0; i < 5; i++);
printf("%d ", i);
return 0;
}
Prints 0 1 2 3 4
Prints 5 only
Infinite loop
Compilation error
What is the result of executing the following code?
#include <stdio.h>
int main() {
for (int j = 0; j < 3; j++) {
printf("Hello World\n");
}
return 0;
}
Hello World Hello World Hello World
3 times Hello World
Compilation error
Hello World
What will be the result of the following code?
#include <stdio.h>
int main() {
int a = 10, b = 0;
printf("%d", a / b);
return 0;
}
0
10
Runtime error (division by zero)
Compilation error
What will happen when you run this program?
#include <stdio.h>
int main() {
int arr[5] = {1, 2, 3, 4, 5};
printf("%d", arr[5]);
return 0;
}
Output is 5
Output is 0
Undefined behavior / garbage value
Compilation error
What’s wrong in the following code?
#include <stdio.h>
int main() {
int i = 1;
while (i <= 5) {
printf("%d ", i);
}
return 0;
}
Infinite loop
Compilation error
Prints 1 to 5
Prints 1 repeatedly and exits
What will be the output of this code?
#include <stdio.h>
int main() {
int a = 7;
if (a = 10) {
printf("Condition is true\n");
}
return 0;
}
Condition is true
Compilation error
Condition is false
No output
What will this code print?
#include <stdio.h>
int main() {
int a = 5;
printf("%d\n", a++ + ++a);
return 0;
}
11
12
Undefined behavior
Compilation error
What is wrong with this loop?
#include <stdio.h>
int main() {
int i;
for (i = 0; i = 5; i++) {
printf("%d ", i);
}
return 0;
}
Prints 5
Infinite loop
Prints 0 to 4
Loop runs only once
What does this program print?
#include <stdio.h>
int main() {
int arr[5] = {1, 2};
for (int i = 0; i < 5; i++) {
printf("%d ", arr[i]);
}
return 0;
}
1 2 0 0 0
1 2 Garbage Garbage Garbage
Compilation error
Undefined behavior
What is the output of this code? #include
1
0
5
Compilation error
#include <stdio.h>
int main() {
int x = 3, y = 4, z = 5;
int result = x < y < z;
printf("%d", result);
return 0;
}
The output of the program is
1
0
5
D) Compilation error
What will be the output of the program?
#include <stdio.h>
int main() {
int x = 10;
if (x > 5);
printf("Greater than 5\n");
return 0;
}
Greater than 5
No output
Compilation error
Depends on compiler
What will be the output of the program?
#include <stdio.h>
int main() {
int a = 5, b = 10;
if (a = b)
printf("Equal\n");
else
printf("Not Equal\n");
return 0;
}
Equal
Not Equal
Compilation error
Runtime error
What is the output of this program?
#include <stdio.h>
int add(int a, int b) {
return a + b;
}
int main() {
printf("%d\n", add(2, 3));
return 0;
}
5
0
Compilation error
Undefined behavior
How many numbers will be printed?
#include <stdio.h>
int main() {
for (int i = 0; i <= 5; i++)
printf("%d ", i);
return 0;
}
5
6
0
infinite
What is the output?
#include <stdio.h>
int main() {
int i = 0;
while (i = 5) {
printf("Looping\n");
break;
}
return 0;
}
No output
Looping
Infinite loop
Compilation error
What is the output of the following code?
#include <stdio.h>
int main() {
int a = 3, b = 4;
printf("%d", a > b ? a : b);
return 0;
}
Undefined behavior
Compilation error
4
3
What will this code output?
#include
Less than 15
15 or more
No output
Compilation error
What will be the output of this program?
#include <stdio.h>
int main() {
int i = 0;
do {
printf("%d ", i);
i++;
} while (i < 3);
return 0;
}
0 1 2
0 1 2 3
1 2
0 1 2 3 4
What will be the output of the following code?
#include
2
2.5
3
Compilation error
What will be the output of this program?
#include <stdio.h>
int main() {
int i = 1;
while (i < 5) {
printf("%d ", i);
i++;
}
return 0;
}
1 2 3 4 5
0 1 2 3 4
1 2 3 4
Compilation error
What will be the output of this program? #include
Undefined behavior
6
9
7
What is the output of the following code?
#include
5
7
3
Compilation error
What will this code output?
#include <stdio.h>
int main() {
for (int i = 0; i < 3; i++) {
printf("%d ", i);
}
return 0;
}
0 1 2 3 4
1 2 3
0 1 2 3
0 1 2
What is the output of this program?
#include <stdio.h>
int main() {
for (int i = 0; i < 5; i++) {
if (i == 3) break;
printf("%d ", i);
}
return 0;
}
No output
0 1 2
0 1 2 3
0 1 2 3 4
What will be the output of this code? #include
Compilation error
No output
Not Equal
Equal
What is printed?
#include <stdio.h>
int main() {
char str[] = "C\0Programming";
printf("%s\n", str);
return 0;
}
C
CProgramming
Programming
Compilation error
What is the output of this program?
#include <stdio.h>
int main() {
int x = 4, y = 5;
if (x == 4 && y == 5) {
printf("True\n");
} else {
printf("False\n");
}
return 0;
}
No output
Compilation error
False
True
What is printed?
#include <stdio.h>
int main() {
int a = 5;
int b = a++;
printf("%d %d\n", a, b);
return 0;
}
6 6
6 5
5 6
5 5
How many lines of output will this program print?
#include <stdio.h>
int main() {
for (int i = 0, j = 5; i < j; i++, j--)
printf("%d %d\n", i, j);
return 0;
}
5
3
2
4
