WorksheetsC Programming Quiz level 2
Total questions: 15
Worksheet time: 8mins
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; }
5
10
15
20
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; }
10
20
30
40
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; }
10
20
0
Compilation Error
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; }
12
14
4
0
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; }
1
2
3
4
What will be the output of the following code? #include int main() { char *ptr = "Hello"; ptr += 3; printf("%s\n", ptr); return 0; }
Hello
lo
llo
Syntax Error
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; }
3
4
5
Compilation Error
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; }
10
5
15
Undefined Behavior
What will be the output of the following code? #include int main() { char str[6] = "Hello"; printf("%c\n", str[5]); return 0; }
o
\0 (null character)
Undefined Behavior
Compilation Error
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; }
2
8
6
0
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; }
25
30
35
Undefined Behavior
What will happen in the following code? #include int main() { int arr[3] = {1, 2, 3}; printf("%d\n", arr[3]); return 0; }
Prints 0
Prints garbage value
Causes a segmentation fault
Compilation Error
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; }
4
1
8
Compilation Error
What will the following code print? #include int main() { char str[] = "Hello\tWorld"; printf("%lu\n", sizeof(str)); return 0; }
11
12
10
13
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; }
3
4
6
Undefined Behavior
