Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

" C Proficiency "

Total questions: 50

Worksheet time: 38mins

Name
Class
Date
1.

Guess the output of the following code:

a)

2.500000

b)

2.000000

c)

2

d)

Compilation Error

2.

How many times will the loop execute?

a)

4

b)

5

c)

6

d)

Infinite times

3.

What is the correct way to declare an integer pointer is

a)

int ptr;

b)

int *ptr;

c)

ptr *int;

d)

int &ptr;

4.

Find the value of x in this code:

a)

10

b)

15

c)

20

d)

40

5.

Output of the following code is:

a)

10

b)

20

c)

30

d)

40

6.

This function returns ---------

a)

Fibonacci sequence

b)

Factorial of n

c)

Sum of first n numbers

d)

Power of n

7.

Output of the following code is:

a)

True

b)

False

c)

Error

d)

Undefined behaviour

8.

What will be the output?

a)

3.14

b)

3.140000

c)

3.1

d)

Error

9.

Guess the output of the following code:

a)

1

b)

2

c)

3

d)

0

10.

Output of the code will be:

a)

H

b)

e

c)

l

d)

Error

11.

Which of the following is a potential issue with using gets()?

a)

It's slow.

b)

It can cause a buffer overflow

c)

It can only read strings of a fixed length.

d)

It's deprecated but still safe to use if you're careful.

12.

What is the purpose of a function pointer?

a)

To store the return value of a function.

b)

To pass a function as an argument to another function.

c)

To create a new function dynamically.

d)

To call a function from a different file.

13.

Output of the below code is:

a)

5 6

b)

6 6

c)

5 7

d)

6 7

14.

Purpose of typedef keyword is---------

a)

To define a constant.

b)

To create an alias for an existing data type.

c)

To declare a function.

d)

To include a header file.

15.

What is the output of the following code:

a)

Hello

b)

Jello

c)

H

d)

Error

16.

What is the output of the following code

a)

5

b)

10

c)

15

d)

Error

17.

What is the difference between const int p and int const p?

a)

They are the same

b)

const int p makes the pointer constant, int const p makes the integer constant

c)

const int p makes the integer constant, int const p makes the pointer constant.

d)

const int *p is invalid syntax.

18.

This code will print -----

a)

o

b)

\0

c)

Error

d)

0

19.

What is a dangling pointer?

a)

A pointer that points to a valid memory location.

b)

A pointer that points to a memory location that has been freed.

c)

A pointer that has not been initialized.

d)

A pointer that points to a constant value.

20.

Identify the correct statement for a switch in C:

a)

Multiple cases can have identical constant expressions

b)

The default statement is optional

c)

switch expressions accept floating-point types

d)

The break is mandatory after every case

21.

Identify the wrong statement:

a)

A for loop can have multiple initialization expressions

b)

The while condition is evaluated before each iteration

c)

A loop variable must be declared globally

d)

Infinite loops are possible in all types of loops

22.

Which of the following causes an infinite loop?

a)

for (i = 0; i < 10; i++)

b)

while (1);

c)

do { } while (i > 10);

d)

for (i = 0; i < 5; i--);

23.

What will be the result of the following code?

a)

Compile-time error

b)

1 2 3 4 5

c)

Infinite Empty loop

d)

1

24.

Which statement is valid for the switch construct?

a)

break is required for the default block

b)

Cases must be in ascending order

c)

All cases must end with a semicolon

d)

case values must be constant

25.

Output of the following code snippet is:

a)

0 0 0

b)

0 1 0

c)

1 1 1

d)

No output

26.

What is the output of the code below?

a)

x is 10

b)

x is not 10

c)

Error

d)

Nothing

27.

Find the output of the below code:

a)

x and y are equal

b)

x and y are not equal

c)

Unpredictable

d)

No output

28.

Which of the following statements about the given line of code is true?

             int p = (int)100;

a)

It is illegal in C

b)

p points to memory location 100, but dereferencing is undefined behavior.

c)

It is always safe to dereference p.

d)

p is an integer variable initialized to 100.

29.

Guess the output:

a)

Equal

b)

Not Equal

c)

Equal Not Equal

d)

Compiler Error

30.

What will be the result of the following expression in C?

                     int a = 5, b = 10, c = 15;

                     a = b++ + --c * a;

a)

a = 5, b = 11, c = 14

b)

a = 15, b = 11, c = 14

c)

a = 5, b = 11, c = 14

d)

a = 20, b = 11, c = 14

31.

Find the output:

a)

1 2

b)

1 2 3

c)

1 2 3 4

d)

 Infinite Loop

32.

What does strlen("C\0Program") return?

a)

9

b)

1

c)

8

d)

10

33.

Given int arr[3][3], which of the following is an incorrect way to access an element?

a)

arr[1][2]

b)

*(arr[1]+2)

c)

((arr+1)+2)

d)

arr[3][3]

34.

Which of the following is used to compare string contents in C?

a)

 ==

b)

strcmp()

c)

=

d)

equals()

35.

After calling free(ptr), what value does ptr hold?

a)

NULL

b)

Garbage value

c)

The original address (dangling pointer)

d)

Zero

36.

Which of the following is not a valid printf format specifier?

a)

%zu

b)

%lld

c)

%p

d)

%n

37.

---------------- keyword is used to declare a function that cannot be modified in other source files.

a)

static

b)

volatile

c)

const

d)

extern

38.

What does the following code print?

a)

10

b)

20

c)

Compile-time Error

d)

Run-time Error

39.

Which of the following function declarations is valid in C?

a)

a) int func(int a, float b = 3.14);

b)

b) int func(int, float);

c)

int func(void int);

d)

void func(void) int;

40.

What is the output of this code snippet?

a)

yes

b)

no

c)

5

d)

6

41.

Fill in the missing condition to ensure a loop runs exactly 5 times:

a)

i <= 5

b)

i != 5

c)

i < 5

d)

i >= 5

42.

What is the missing statement to declare a pointer to a function that takes two integers and returns a float?

a)

float *func(int, int);

b)

float (*func)(int, int);

c)

float (func)(int, int);

d)

float (*func())(int, int);

43.

What is the missing access specifier for bit-fields in this struct?

a)

char

b)

unsigned int

c)

float

d)

int

44.

Fill in the missing statement to copy a string in C:

a)

strcat

b)

strncpy

c)

strcpy

d)

strcmp

45.

Which control statement is missing to stop infinite execution in the following loop?

a)

break

b)

continue

c)

return

d)

goto

46.

To round off x (float), to an int value, the correct way to do is

a)

y = (int)(x + 0.5)

b)

y = int(x + 0.5)

c)

y = (int)x + 0.5

d)

y = (int)((int)x + 0.5)

47.

What will be the output of the following C code?

a)

128

b)

-128

c)

a) Compiler-dependent

d)

None of these

48.

Pointer arithmetic is not possible on ___.

a)

Integer pointers

b)

Float pointers

c)

Character pointers

d)

Void pointers

49.

Find the output:

a)

20

b)

24

c)

4

d)

18

50.

Find the output:

a)

10

b)

11

c)

12

d)

13