wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

C Programming Fundamentals

Total questions: 23

Worksheet time: 12mins

Name
Class
Date
1.

What will be the output of the following code snippet: int a = 5; if(a > 3) { printf("Hello"); } else { printf("World"); }

a)

Greetings

b)

Salutations

c)

Hello

d)

Hi

2.

Identify the data type of the variable 'x' in the following code: float x = 10.5;

a)

int

b)

float

c)

string

d)

double

3.

What is the result of the following expression: 10 / 3?

a)

4.0

b)

2.5

c)

3.5

d)

3.3333

4.

What will be the output of the following code: int a = 10; a++; printf("%d", a);

a)

11

b)

10

c)

9

d)

12

5.

What is the purpose of the switch statement in C?

a)

To create loops in C programming.

b)

To define functions in C.

c)

To handle errors in C code.

d)

The purpose of the switch statement in C is to simplify multi-way branching based on the value of a variable.

6.

What will be the output of the following code: int a = 5; int b = 10; int c = (a > b) ? a : b; printf("%d", c);

a)

15

b)

10

c)

5

d)

0

7.

What is the result of the following operation: 5 + 2 * 3?

a)

11

b)

8

c)

9

d)

10

8.

What will be the output of the following code: int a = 5; a += 2; printf("%d", a);

a)

7

b)

6

c)

8

d)

5

9.

What is the data type of the variable 'y' in the following code: char y = 'A';

a)

float

b)

char

c)

string

d)

int

10.

What will be the output of the following code: int a = 5; int b = 2; printf("%d", a / b);

a)

1

b)

2.5

c)

3

d)

2

11.

What is the result of the following expression: (float)10 / 3?

a)

3.3333

b)

2.6

c)

4.5

d)

3.0

12.

What will be the output of the following code: int a = 5; a--; printf("%d", a);

a)

3

b)

4

c)

5

d)

0

13.

What is the purpose of type conversion in C?

a)

To create new data types in C

b)

To improve the performance of the program

c)

To reduce the memory usage of variables

d)

The purpose of type conversion in C is to enable operations between different data types and ensure compatibility.

14.

What will be the output of the following code: int a = 5; int b = 10; if(a < b) { printf("True"); } else { printf("False"); }

a)

Maybe

b)

False

c)

True

d)

Not Sure

15.

What is the result of the following operation: 10 % 3?

a)

1

b)

3

c)

10

d)

0

16.

What will be the output of the following code: int a = 5; int b = 5; if(a == b) { printf("Equal"); } else { printf("Not Equal"); }

a)

Equal

b)

Undefined

c)

Not Equal

d)

Error

17.

What is the precedence of the operators in the expression: 2 + 3 * 4?

a)

Addition (+) has higher precedence than multiplication (*).

b)

Multiplication (*) and addition (+) are evaluated from left to right.

c)

Both operators have the same precedence.

d)

Multiplication (*) has higher precedence than addition (+).

18.

What will be the output of the following code: int a = 5; int b = 3; printf("%d", a - b++);

a)

5

b)

2

c)

3

d)

1

19.

What is the result of the following expression: (int)5.7 + (int)2.3?

a)

9

b)

7

c)

6

d)

8

20.

What will be the output of the following code: switch(a) { case 1: printf("One"); break; case 2: printf("Two"); break; default: printf("Default"); } where a = 3?

a)

Two

b)

One

c)

Three

d)

Default

21.

What will be the output of the following code: int a = 10; int b = 5; printf("%d", a % b);

a)

1

b)

0

c)

5

d)

2

22.

What is the result of the following expression: (double)9 / 4?

a)

2.5

b)

2.0

c)

2.25

d)

3.0

23.

What will be the output of the following code: int a = 3; int b = 4; printf("%d", a * b + a);

a)

12

b)

15

c)

7

d)

10