wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Learn2Code-17-09-2025

Total questions: 30

Worksheet time: 15mins

Name
Class
Date
1.

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;
}

a)

Prints 0 1 2 3 4

b)

Prints 5 only

c)

Infinite loop

d)

Compilation error

2.

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;
}

a)

Hello World Hello World Hello World

b)

3 times Hello World

c)

Compilation error

d)

Hello World

3.

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;

}

a)

0

b)

10

c)

Runtime error (division by zero)

d)

Compilation error

4.

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;

}

a)

Output is 5

b)

Output is 0

c)

Undefined behavior / garbage value

d)

Compilation error

5.

What’s wrong in the following code?

#include <stdio.h>

int main() {

int i = 1;

while (i <= 5) {

printf("%d ", i);

}

return 0;

}

a)

Infinite loop

b)

Compilation error

c)

Prints 1 to 5

d)

Prints 1 repeatedly and exits

6.

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;

}

a)

Condition is true

b)

Compilation error

c)

Condition is false

d)

No output

7.

What will this code print?

#include <stdio.h>

int main() {

int a = 5;

printf("%d\n", a++ + ++a);

return 0;

}

a)

11

b)

12

c)

Undefined behavior

d)

Compilation error

8.

What is wrong with this loop?

#include <stdio.h>

int main() {

int i;

for (i = 0; i = 5; i++) {

printf("%d ", i);

}

return 0;

}

a)

Prints 5

b)

Infinite loop

c)

Prints 0 to 4

d)

Loop runs only once

9.

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;

}

a)

1 2 0 0 0

b)

1 2 Garbage Garbage Garbage

c)

Compilation error

d)

Undefined behavior

10.

What is the output of this code? #include int main() { int x = 5, y = 3; int z = x && y; printf("%d", z); return 0; }

a)

1

b)

0

c)

5

d)

Compilation error

11.

#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

a)

1

b)

0

c)

5

d)

D) Compilation error

12.

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;

}

a)

Greater than 5

b)

No output

c)

Compilation error

d)

Depends on compiler

13.

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;

}

a)

Equal

b)

Not Equal

c)

Compilation error

d)

Runtime error

14.

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;

}

a)

5

b)

0

c)

Compilation error

d)

Undefined behavior

15.

How many numbers will be printed?

#include <stdio.h>

int main() {

for (int i = 0; i <= 5; i++)

printf("%d ", i);

return 0;

}

a)

5

b)

6

c)

0

d)

infinite

16.

What is the output?

#include <stdio.h>

int main() {

int i = 0;

while (i = 5) {

printf("Looping\n");

break;

}

return 0;

}

a)

No output

b)

Looping

c)

Infinite loop

d)

Compilation error

17.

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;

}

a)

Undefined behavior

b)

Compilation error

c)

4

d)

3

18.

What will this code output? #include int main() { int x = 10; if (x < 15) { printf("Less than 15\n"); } else { printf("15 or more\n"); } return 0; }

a)

Less than 15

b)

15 or more

c)

No output

d)

Compilation error

19.

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;

}

a)

0 1 2

b)

0 1 2 3

c)

1 2

d)

0 1 2 3 4

20.

What will be the output of the following code? #include int main() { int a = 5, b = 2; printf("%d", a / b); return 0; }

a)

2

b)

2.5

c)

3

d)

Compilation error

21.

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;

}

a)

1 2 3 4 5

b)

0 1 2 3 4

c)

1 2 3 4

d)

Compilation error

22.

What will be the output of this program? #include int main() { int a = 1, b = 2, c = 3; printf("%d", a + b * c); return 0; }

a)

Undefined behavior

b)

6

c)

9

d)

7

23.

What is the output of the following code? #include int main() { int x = 5; if (x > 3) { x += 2; } else { x -= 2; } printf("%d", x); return 0; }

a)

5

b)

7

c)

3

d)

Compilation error

24.

What will this code output?

#include <stdio.h>

int main() {

for (int i = 0; i < 3; i++) {

printf("%d ", i);

}

return 0;

}

a)

0 1 2 3 4

b)

1 2 3

c)

0 1 2 3

d)

0 1 2

25.

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;

}

a)

No output

b)

0 1 2

c)

0 1 2 3

d)

0 1 2 3 4

26.

What will be the output of this code? #include int main() { int x = 4; if (x == 4) { printf("Equal\n"); } else { printf("Not Equal\n"); } return 0; }

a)

Compilation error

b)

No output

c)

Not Equal

d)

Equal

27.

What is printed?

#include <stdio.h>

int main() {

char str[] = "C\0Programming";

printf("%s\n", str);

return 0;

}

a)

C

b)

CProgramming

c)

Programming

d)

Compilation error

28.

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;

}

a)

No output

b)

Compilation error

c)

False

d)

True

29.

What is printed?

#include <stdio.h>

int main() {

int a = 5;

int b = a++;

printf("%d %d\n", a, b);

return 0;

}

a)

6 6

b)

6 5

c)

5 6

d)

5 5

30.

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;

}

a)

5

b)

3

c)

2

d)

4