Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C Programming Quiz

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

In the following code, what is the output?

int a[] = {1, 2, 3};

int *b[3];

for(int k=0; k<3; k++)

b[k] = a + k;

printf("%d %d %d", *b[0], *b[1], *b[2]);

a)

A) 1 1 1

b)

B) 1 2 3

c)

C) Address values

d)

D) Compilation error

2.

Which statement is true about this declaration? int **c[3];

a)

A) c is a double pointer

b)

B) c is a pointer to array of int

c)

C) c is an array of pointers to pointer to int

d)

D) c is a 2-D array

3.

What is the output of the following code?

int a = 2, *p, **q;

p = &a;

q = &p;

printf("%d %d %d", a, *p, *q);

a)

A) 2 2 2

b)

B) 2 2 address

c)

C) 2 address address

d)

D) Compilation error

4.

What will be printed?

void fun(int *ptr)

{

*ptr = 30;

}

int main()

{

int y = 20;

fun(&y);

printf("%d", y);

}

a)

A) 20

b)

B) 30

c)

C) Garbage value

d)

D) Runtime error

5.

Identify the error in the following code:

int t[] = {1,2,3,4,5};

int *p, *q;

p = t;

q = p[1];

a)

A) p = t is invalid

b)

B) q = p[1] assigns int to pointer

c)

C) Missing memory allocation

d)

D) No error

6.

What is the issue in the code below?

char *c;

float x = 10;

c = &x;

a)

A) Syntax error

b)

B) Assigning float to char

c)

C) Incompatible pointer types

d)

D) No error

7.

What will be the output?

int x;

int *ptr = &x;

*ptr = 5;

*ptr += 1;

(*ptr)++;

printf("%d", x);

a)

A) 0

b)

B) 5

c)

C) 6

d)

D) 7

8.

Assume: int = 4 bytes, char = 1 byte, pointer = 4 bytes.

What is the output?

int arri[] = {1,2,3};

int *ptri = arri;

printf("%d %d", sizeof(arri), sizeof(ptri));

a)

A) 3 3

b)

B) 12 12

c)

C) 12 4

d)

D) 4 12

9.

Which is the correct way to access a structure member using a pointer? (assume that the variable name is 'a' and the value to assign is 5)

a)

A) *ptr.a = 5;

b)

B) ptr.a = 5;

c)

C) (*ptr).a = 5;

d)

D) ptr->a=5;

e)

E) both C and D

10.

Assume float takes 4 bytes. What is the output?

float arr[5] = {2.5, 1.0, 1.5, 9.5, 1.5};

float *ptr1 = &arr[0];

float *ptr2 = ptr1 + 2;

printf("%f, %d", *ptr2, ptr2 - ptr1);

a)

A) 1.5, 2.5

b)

B) 1.5, 2

c)

C) 2.5, 2

d)

D) 12.5, address of arr[0]