Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Playing with C

Total questions: 20

Worksheet time: 20mins

Name
Class
Date
1.

Consider the following C program segment

# include <stdio.h>

int main()

{

char s1[7654] = "1234", *p;

p = s1 + 2;

*p = '0';

printf("%s", s1);

}

a)

7054

b)

7054

c)

1204

d)

9876

2.

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 ____

a)

11

b)

1

c)

15

d)

Compiler Error

3.

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 ____

a)

79671

b)

79671

c)

69671

d)

696671

4.

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

}

a)

-67

b)

67

c)

-62

d)

62

5.

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 ____

a)

uup,f,4,fokcuf

b)

up,f,0,fokcuf

c)

up,f,1,fokcuf

d)

down,f,2,fokcuf

6.

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 ____

a)

0

b)

True

c)

Runtime Error

d)

False

7.

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 ____

a)

123456789:;<=>?@ABCDEFGHIJ

b)

ABCDEFGHIJ:;<=>?@123456789

c)

123456789:;<=>?@abcdefghij

d)

123456789:;<=>?@ABCDEFGHIJ

8.

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 ____

a)

5f

b)

5

c)

b

d)

b2

9.

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 ____

a)

7 7 4 8

b)

7 8 7 4

c)

4 8 7 7

d)

4 8 7 7

10.

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 ____

a)

20 10

b)

10 20

c)

Compiler Error

d)

Runtime Error

11.

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;

}

a)

12

b)

11

c)

10

d)

9

12.

What is the output of this code?

int i = (1, 2, 3); printf("%d", i);

a)

14

b)

11

c)

10

d)

3

13.

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

a)

1

b)

11

c)

2

d)

4

14.

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;

}

a)

12

b)

42

c)

41

d)

11

15.

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]);

a)

0

b)

1

c)

2

d)

3

16.

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;

}

a)

0

b)

1

c)

2

d)

3

17.

What is the output of the following code in C?

char *s = "DKTE Quiz";

    int n = 6;

    printf("%.*s", n, s);

    return 0;

a)

DKTE Q

b)

DKTE

c)

DKTE Qu

d)

None

18.

What is the output of the following code?

            #include<stdio.h>

int main()

{

            printf("%d", printf("%d", 4321));

            return 0;

}

a)

44321

b)

41234

c)

43214

d)

12344

19.

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;

}

a)

12

b)

16

c)

8

d)

Compiler Error

20.

What is the output of the following code?

           

struct {

            short s[14];

            union {

                        float y;

                        long z;

            }u;

} t;

a)

36 bytes

b)

44 bytes

c)

24 bytes

d)

25 bytes