wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

C Programming Worksheet Questions

Total questions: 25

Worksheet time: 13mins

Name
Class
Date
1.

What is the output of the following C code? #include int main() { float x = 'a'; printf("%f", x); return 0; }

a)

97.000000

b)

a

c)

0.000000

d)

Compilation error

2.

Which keyword is used to explicitly exit a loop or switch statement?

a)

continue

b)

exit

c)

break

d)

return

3.

Which of the following is a derived data type in C?

a)

int

b)

char

c)

array

d)

double

4.

What is the value of a after the following code snippet executes? int a = 10; a += 5;

a)

5

b)

10

c)

15

d)

Undefined behaviour

5.

What is the output of the following C code snippet? #include int main() { int x = 5; printf("%d", !x); return 0; }

a)

1

b)

0

c)

-1

d)

Error

6.

Which of the following is the correct syntax for the conditional (ternary) operator in C?

a)

condition < expression1 ? expression2;

b)

condition ? expression1 : expression2;

c)

condition : expression1 ? expression2;

d)

condition ? expression1 < expression2;

7.

Which loop is used when you want to iterate through a range of values and know the number of iterations beforehand?

a)

for loop

b)

while loop

c)

do-while loop

d)

none of the above

8.

How can you exit a loop prematurely if a certain condition is met?

a)

using the continue statement

b)

using the break statement

c)

using the return statement

d)

using the exit statement

9.

What is the purpose of the continue statement in a loop?

a)

to exit the loop

b)

to skip the rest of the current iteration and move to the next iteration

c)

to repeat the current iteration

d)

to start a new loop

10.

In situations where we need to execute body of the loop before testing the condition, we should use __________.

a)

for loop

b)

while loop

c)

do while loop

d)

nested for loop

11.

What is the index number of the last element of an array with 29 elements?

a)

29

b)

28

c)

0

d)

Programmer-defined

12.

What will sizeof(arr) return if arr is declared as int arr[5];?

a)

5

b)

10

c)

20

d)

Compiler error

13.

What is the output of this code? int arr[3] = {10}; printf("%d %d %d", arr[0], arr[1], arr[2]);

a)

10 10 10

b)

10 0 0

c)

0 0 0

d)

Garbage values

14.

Which of the following is a valid array initialization?

a)

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

b)

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

c)

Both a and b

d)

Neither a nor b

15.

What is the index of the first element in a C array?

a)

0

b)

1

c)

-1

d)

Depends on compiler

16.

Which header file is required to use string functions like strlen(), strcpy(), and strcat()?

a)

stdlib.h

b)

string.h

c)

stdio.h

d)

conio.h

17.

What is the correct way to declare a string in C?

a)

char str[] = "Hello";

b)

string str = "Hello";

18.

Which of the following functions is used to find the length of a string?

a)

strlen()

b)

strlength()

c)

length()

d)

str_len()

19.

The function __________ is used to copy one string to another in C.

a)

strcpy

b)

strcat

c)

strrev

d)

strcmp

20.

What is the output of the following code? char str[10]; strcpy(str, "Hello"); printf("%s", str);

a)

Error

b)

Garbage value

c)

Hello

d)

Hell

21.

What will be the output of the following code? int add(int a, int b) { return a + b; } int main() { printf("%d", add(2, 3)); return 0; }

a)

2

b)

3

c)

5

d)

Error

22.

Which of the following is true about recursion in C?

a)

Every recursive function must have a base case

b)

Recursion is faster than loops

c)

Recursion cannot use global variables

d)

Stack is not used in recursion

23.

What is recursion?

a)

A function that calls itself

b)

A function that returns a pointer

c)

A function that calls another function

d)

A function with no return type

24.

What is the base condition in recursion?

a)

The first condition

b)

The stopping condition

c)

The return type

d)

None of the above

25.

What is the correct syntax to declare a function in C?

a)

function int myFunc();

b)

int myFunc();

c)

declare int myFunc();

d)

int = myFunc();