WorksheetsPlaying with C
Total questions: 20
Worksheet time: 20mins
Consider the following C program segment
# include <stdio.h>
int main()
{
char s1[7654] = "1234", *p;
p = s1 + 2;
*p = '0';
printf("%s", s1);
}
7054
7054
1204
9876
Consider the following C program.
int main () {
int a[4] [5] = { {6, 7,8, 9, 10},
{1, 2, 3, 4, 5},
{11, 12, 13, 14, 15},
{16, 17,18, 19, 20}
};
printf("%d\n", ((a+**a+1)+3));
return(0);
}
The output of the program is ____
11
1
15
Compiler Error
Consider the following C program.
int f(int x, int py, int *ppz)
{
int y, z;
**ppz <<= 11; z = **ppz;
py ^= 11; y = py;
x += 11;
return x+y+z;
}
int main()
{
int c, b, *a;
c = 17; b = &c; a = &b;
printf("%d", f(c, b, a));
}
The output of the program is ____
79671
79671
69671
696671
What is the output printed after running the program ?
#include <stdio.h>
int f (int * qq, int n)
{
if (n <= 0) return 0;
else return (f (qq+7, n-4), qq[0] - qq[1]);
}
int main ()
{
int a[] = {15, 77, 147, 44, 78};
printf(" %d", f(a, 5));
}
-67
67
-62
62
Consider the following C program.
#include <stdio.h>
struct test {
int i;
char *c;
}st[] = {5, "dkte", 4, "yup", 6, "ffokcuf", 8, "vampire", 7, "almost"};
main ()
{
struct test *p = st;
p += 1;
++p -> c;
printf("%s,", p++ -> c);
printf("%c,", *++p -> c);
printf("%d,", p[5].i);
printf("%s \n", p -> c);
}
The output of the program is ____
uup,f,4,fokcuf
up,f,0,fokcuf
up,f,1,fokcuf
down,f,2,fokcuf
Consider the following C program.
#include <stdio.h>
int main(void)
{
int a = 30;
int* d = &a;
char n = 'Z';
char* z = &n;
d[0] = z[0];
printf((*d == *z) ? "False" : "True");
}
The output of the program is ____
0
True
Runtime Error
False
Consider the following C program.
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char x = '1';
char* y = (char*)malloc(sizeof(char));
y = &x;
for (int i = 0; i < 26; i++) {
printf("%c", x);
y[0] += 1;
}
}
The output of the program is ____
123456789:;<=>?@ABCDEFGHIJ
ABCDEFGHIJ:;<=>?@123456789
123456789:;<=>?@abcdefghij
123456789:;<=>?@ABCDEFGHIJ
Consider the following C program.
#include <stdio.h>
struct A {
int a1;
struct B {
int a1;
} A1;
} Ex1;
int main(void)
{
Ex1.a1 = 7;
Ex1.A1.a1 = 5;
int* x = &Ex1.a1;
int* y = &Ex1.A1.a1;
x = y;
char** z = (char**)&x;
*z[0] = x[0];
printf("%x", **z);
}
The output of the program is ____
5f
5
b
b2
Consider the following C program.
#include <stdio.h>
int main()
{
int a[][3] = {4,5,8,5,7,6};
int (*ptr)[3] = a;
printf("%d %d ", (*ptr)[0], (*ptr)[2]);
++ptr;
printf("%d %d\n", (*ptr)[1], (*ptr)[1]);
return 0;
}
The output of the program is ____
7 7 4 8
7 8 7 4
4 8 7 7
4 8 7 7
Consider the following C program.
#include <stdio.h>
int fun(int 1arr[]) {
1arr = arr+1;
printf("%d ", 1arr[0]);
}
int main(void) {
int arr[2] = {10, 20};
fun(arr);
printf("%d", arr[0]);
return 0;
}
The output of the program is ____
20 10
10 20
Compiler Error
Runtime Error
What is the output of this code?
int i = 10; void f(void) {
int i = 5;
i = 7;
}
void g() {
i = 9;
}
int main() {
i = 1;
g(); f();
printf("%d", i);
return 0;
}
12
11
10
9
What is the output of this code?
int i = (1, 2, 3); printf("%d", i);
14
11
10
3
What is the output of this code?
int res = 1;
for(int flag = 0; flag < 5; flag++)
{
if((flag > 2) && (res > 2))
res += 7;
}
printf("%i", res);
1
11
2
4
What is the output of this code?
#define macro(r, a, v) v##a##r
#define DECVAR macro(r, a, v)
#define PTR int*
int main() {
int DECVAR = 42;
PTR p = &var;
printf("%d", *p);
return 0;
}
12
42
41
11
What is the output of the following code?
int* arr = (int*)malloc(10*sizeof(int));
arr[0] = 20;
arr[1] = 21;
arr[2] = 1; printf("%d", arr + (arr + 2) - arr[1]);
0
1
2
3
What is the output of the following code?
#include <stdio.h>
#define A (-B)
#define B (-C)
#define C (-2)
int main() {
printf("%d", A + B);
return 0;
}
0
1
2
3
What is the output of the following code in C?
char *s = "DKTE Quiz";
int n = 6;
printf("%.*s", n, s);
return 0;
DKTE Q
DKTE
DKTE Qu
None
What is the output of the following code?
#include<stdio.h>
int main()
{
printf("%d", printf("%d", 4321));
return 0;
}
44321
41234
43214
12344
What is the output of the following code?
union test
{
int x;
char arr[12];
int y;
};
int main()
{
printf("%d", sizeof(union test));
return 0;
}
12
16
8
Compiler Error
What is the output of the following code?
struct {
short s[14];
union {
float y;
long z;
}u;
} t;
36 bytes
44 bytes
24 bytes
25 bytes
