wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C Programming - Medium

Total questions: 10

Worksheet time: 4mins

Name
Class
Date
1.

Whether C code will compile without main() function?

a)

Yes

b)

No

2.

Format specifier for size_t is:

a)

%s

b)

%p

c)

%zu

d)

%ld

e)

%i

3.

What is output of this code:


#include <stdio.h>


int main(){

int y = 3;

printf("%d %d %d",y,y,y++,++y);

}

a)

3 3 3

b)

5 5 4

c)

3 3 4

d)

4 4 5

4.

What is output of this code:


#include <stdio.h>

#define ARR_SIZE 10

int main(){

int arr[ARR_SIZE] = {-1};

int *ptr1 = &(arr[0]), *ptr2 = &(arr[4]);

printf("%p",ptr2-ptr1);}

a)

4

b)

Compile Error

c)

0x4

d)

0x16

e)

16

5.

Select existing signals

a)

SIGILL

b)

SIGTERM

c)

SIGRET

d)

SIGEXT

e)

SIGFPE

6.

In which libraries NULL macro is defined?

a)

stdlib.h

b)

stdio.h

c)

assert.h

d)

stddef.h

e)

stdbool.h

7.

Which macro may return 31?


int x = 2, y= 3, z;

z= RAT(x++,++y);

a)

#define RAT (A,B) ( ((A) * (A)) + ((B) * (B)) )

b)

#define RAT (A,B) ( ((A) * (2)) + ((B) * (2)) )

c)

#define RAT(A,B) ( ((A) * (A)) + ((B) * (B)) )

d)

#define RAT(A,B) ( ((A) * (2)) + ((B) * (2)) )

e)

#define RAT(A,B) ( ((A) * (B)) + ((B) * (B)) )

8.

What is output for this code:


int *p = (int*)malloc(sizeof(int));

int *q = (int*)realloc(p, sizeof(int));

*p = 1; *q = 2;

if (p == q) printf("%d%d", *p, *q);

a)

Compile Error

b)

12

c)

Undefined Behaviour

d)

22

e)

Runtime Error

9.

What is output for this code:


volatile static int x = 15;

fork();

printf("%d ",++x);

if (fork() == 0) {

x += 5; printf("%d ", x);

}else {

x -= 5; printf("%d ", x);}

a)

16 11 16 21 16 11 16 21

b)

16 11 16 21

c)

16 11 17 11 18 21 19 21

d)

11 16 11 16 21 16 21

e)

16 11 16 11 16 21 16 21

10.

Which one is NOT a C compiler

a)

GCC

b)

CFront

c)

Clang

d)

Icc

e)

QuickC