wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

CB - CD

Total questions: 20

Worksheet time: 8mins

Name
Class
Date
1.

Which of the following function calculates square of 'x' in c?

a)

sqr(x)

b)

pow(2,x)

c)

power(x,2)

d)

pow(x,2)

2.

How will you print \n on the screen?

a)

printf("\n");

b)

printf("\\n");

c)

printf('\n');

d)

printf("\n\");

3.

What will be the output of the following C code?

a)

hello

b)

no

c)

hi

d)

error

4.

What will be the output of the following C code?

a)

hi

b)

how are u

c)

hello

d)

hihello

5.

What will be the output of the following C code? (Assuming that we have entered the value 1 in the standard input)

a)

1 2

b)

1

c)

2

d)

error

6.

What will be the output of the following C code?

a)

yes

b)

yes default

c)

default

d)

error

7.

Which of the following is not a valid C variable name?

a)

int number;

b)

float rate;

c)

int $main;

d)

int variable_count;

8.

Which keyword is used to prevent any changes in the variable within a C program?

a)

immutable

b)

const

c)

mutable

d)

volatile

9.

What is the output of this code?
int a = 5, b = 2;

printf("%d", a / b);

a)

2.5

b)

2.0

c)

2

d)

0

10.

Which symbol is used to write a single-line comment in C?

a)

/* comment */

b)

# comment

c)

// comment

d)

-- comment

11.

Which operator is used to assign a value to a variable?

a)

==

b)

=

c)

:=

d)

<-

12.

What will be the output of the following code?
int a = 5, b = 2;

printf("%d", a + b * a);

a)

35

b)

15

c)

20

d)

25

13.

What will be the value of x after this operation?
int x = 10;

x %= 3;

a)

3

b)

1

c)

0

d)

10

14.

Which of the following performs a bitwise AND operation?

a)

&

b)

&&

c)

and

d)

|

15.

What will be printed?
int x = 5;

printf("%d", x > 2 ? x < 10 ? 100 : 200 : 300);

a)

100

b)

200

c)

300

d)

10

16.

What is the result of this expression?
int x = 3;

printf("%d", x = x == 3);

a)

3

b)

1

c)

0

d)

Error

17.

Guess the output:
int a = 2, b = 5;

printf("%d", a++ * ++b);

a)

10

b)

12

c)

15

d)

Undefined

18.

Output of this?
int x = 5;

if (x++ == 5)

printf("%d", x);

else

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

a)

5

b)

6

c)

7

d)

4

19.

Guess the output:

int a = 1, b = 2;

switch (a) {

case 1:

switch (b) {

case 1: printf("X"); break;

case 2: printf("Y"); break;

}

case 2: printf("Z");

}

a)

XZ

b)

Y

c)

X

d)

YZ

20.

int x = 1;

switch (x * 2) {

case 1+1: printf("A"); break;

case 2+2: printf("B"); break;

default: printf("C");

}

a)

A

b)

B

c)

C

d)

ERROR