Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C Programming Quiz level 2

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

What will be the output of the following code? #include int main() { int a = 5; int *p = &a; *p += *p * 2; printf("%d\n", a); return 0; }

a)

5

b)

10

c)

15

d)

20

2.

What will be the output of the following code? #include int main() { int arr[] = {10, 20, 30, 40, 50}; int *ptr = arr + 2; printf("%d\n", *ptr); return 0; }

a)

10

b)

20

c)

30

d)

40

3.

What will be the output of the following code? #include void update(int x) { x = x * 2; } int main() { int a = 10; update(a); printf("%d\n", a); return 0; }

a)

10

b)

20

c)

0

d)

Compilation Error

4.

What will be the output of the following code? #include int main() { int x = 5; // binary: 0101 int y = 9; // binary: 1001 printf("%d\n", x ^ y); return 0; }

a)

12

b)

14

c)

4

d)

0

5.

What will be the output of the following code? #include int main() { int arr[2][2] = {{1, 2}, {3, 4}}; printf("%d\n", *(*(arr + 1) + 1)); return 0; }

a)

1

b)

2

c)

3

d)

4

6.

What will be the output of the following code? #include int main() { char *ptr = "Hello"; ptr += 3; printf("%s\n", ptr); return 0; }

a)

Hello

b)

lo

c)

llo

d)

Syntax Error

7.

What will be the output of the following code? #include int main() { int a = 1, b = 0, c = 3; if (a || ++b && c) { c += a; } printf("%d\n", c); return 0; }

a)

3

b)

4

c)

5

d)

Compilation Error

8.

What will be the output of the following code? #include void change(int *x) { *x = *x + 5; } int main() { int a = 10; change(&a); printf("%d\n", a); return 0; }

a)

10

b)

5

c)

15

d)

Undefined Behavior

9.

What will be the output of the following code? #include int main() { char str[6] = "Hello"; printf("%c\n", str[5]); return 0; }

a)

o

b)

\0 (null character)

c)

Undefined Behavior

d)

Compilation Error

10.

What will be the output of the following code? #include int main() { int a = 8; a |= 2; a &= 6; printf("%d\n", a); return 0; }

a)

2

b)

8

c)

6

d)

0

11.

What will be the output of the following code? #include int main() { int x = 5; int y = x++ * ++x; printf("%d\n", y); return 0; }

a)

25

b)

30

c)

35

d)

Undefined Behavior

12.

What will happen in the following code? #include int main() { int arr[3] = {1, 2, 3}; printf("%d\n", arr[3]); return 0; }

a)

Prints 0

b)

Prints garbage value

c)

Causes a segmentation fault

d)

Compilation Error

13.

What will be the output of the following code if sizeof(int) = 4, sizeof(char) = 1, and sizeof(double) = 8? #include int main() { int x = 10; printf("%lu\n", sizeof(x + 2.5)); return 0; }

a)

4

b)

1

c)

8

d)

Compilation Error

14.

What will the following code print? #include int main() { char str[] = "Hello\tWorld"; printf("%lu\n", sizeof(str)); return 0; }

a)

11

b)

12

c)

10

d)

13

15.

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

a)

3

b)

4

c)

6

d)

Undefined Behavior