Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C Programming MCQs

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

Which of the following is NOT a valid data type in C?

a)

int

b)

float

c)

string

d)

char

2.

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

a)

2num

b)

_value

c)

break

d)

@data

3.

What will be the value of x after this expression is evaluated? int x = 5; x = x + 2 * 3;

a)

11

b)

21

c)

16

d)

10

4.

Which of the following is a valid statement in C?

a)

if (x > 10) then y = 5;

b)

x = y = z = 0;

c)

print("Hello");

d)

input(x);

5.

In C, the if-else conditional statement is mainly used for:

a)

Repeating a block of code

b)

Making decisions

c)

Declaring variables

d)

Defining arrays

6.

Which keyword is used to define a function in C?

a)

function

b)

def

c)

void

d)

fun

7.

What is the main characteristic of a recursive function?

a)

It calls another function

b)

It calls itself

c)

It executes infinitely

d)

It runs faster than normal functions

8.

How do you declare a single-dimensional array of 5 integers in C?

a)

int arr[5];

b)

array int arr(5);

c)

int arr = [5];

d)

arr int[5];

9.

In a 2D array int a[3][4];, how many elements can it store?

a)

7

b)

12

c)

34

d)

64

10.

Which of the following best describes an expression in C?

a)

A constant value

b)

A variable declaration

c)

A combination of variables, constants, and operators

d)

A statement ending with a semicolon

11.

What is the primary difference in memory allocation between a C struct and a union?

a)

Structures allocate memory for only the first element, while unions allocate for all.

b)

Structures allocate separate memory for each element, while unions share the same memory location for all elements.

c)

Unions allocate separate memory for each element, while structures share the same memory location for all elements.

d)

Both structures and unions always allocate separate memory for each element.

12.

Which of the following are known as user-defined data types in C?

a)

int, float, char

b)

struct, union, enum.

c)

array, pointer

d)

void, long

13.

Unlike arrays, what kind of data can a C struct be used for storing?

a)

Only homogeneous data (data of the same type).

b)

Only character data.

c)

Heterogeneous data (data of different data types).

d)

Only integer data.

14.

What is a pointer in C programming?

a)

A variable that stores a numerical value.

b)

A variable that stores the memory address of another variable as its value.

c)

A constant that stores a fixed memory location.

d)

A function that returns a memory address.

15.

Which operator is used for dereferencing a pointer to indirectly access the object it references?

a)

& (address-of operator)

b)

. (direct member access operator)

c)

* (indirection operator or value-at-operator).

d)

-> (indirect member access operator)

16.

Why is file handling necessary in C programming?

a)

To speed up program execution only.

b)

To ensure data is lost when the program terminates.

c)

To preserve data even after the program terminates and to handle large amounts of data efficiently.

d)

To display data only on the console.

17.

Which file opening mode in C is used to open a file for both reading and writing, overwriting its contents if the file already exists?

a)

r+

b)

a+

c)

w+.

d)

rb

18.

When defining an enum in C like enum weekdays {Sunday, Monday, Tuesday};, what is the default integral value assigned to Sunday?

a)

-1

b)

0.

c)

1

d)

Undefined

19.

Which preprocessor directive is used to define a macro in C?

a)

#include

b)

#ifndef

c)

#define.

d)

#undef

20.

What operator(s) can be used to access members of a structure object?

a)

-> (arrow operator) only.

b)

. (dot operator) only.

c)

Both . (dot operator) and -> (arrow operator).

d)

& (address-of operator) only.