WorksheetsC Programming MCQs
Total questions: 20
Worksheet time: 10mins
Which of the following is NOT a valid data type in C?
int
float
string
char
Which of the following is a valid variable name in C?
2num
_value
break
@data
What will be the value of x after this expression is evaluated? int x = 5; x = x + 2 * 3;
11
21
16
10
Which of the following is a valid statement in C?
if (x > 10) then y = 5;
x = y = z = 0;
print("Hello");
input(x);
In C, the if-else conditional statement is mainly used for:
Repeating a block of code
Making decisions
Declaring variables
Defining arrays
Which keyword is used to define a function in C?
function
def
void
fun
What is the main characteristic of a recursive function?
It calls another function
It calls itself
It executes infinitely
It runs faster than normal functions
How do you declare a single-dimensional array of 5 integers in C?
int arr[5];
array int arr(5);
int arr = [5];
arr int[5];
In a 2D array int a[3][4];, how many elements can it store?
7
12
34
64
Which of the following best describes an expression in C?
A constant value
A variable declaration
A combination of variables, constants, and operators
A statement ending with a semicolon
What is the primary difference in memory allocation between a C struct and a union?
Structures allocate memory for only the first element, while unions allocate for all.
Structures allocate separate memory for each element, while unions share the same memory location for all elements.
Unions allocate separate memory for each element, while structures share the same memory location for all elements.
Both structures and unions always allocate separate memory for each element.
Which of the following are known as user-defined data types in C?
int, float, char
struct, union, enum.
array, pointer
void, long
Unlike arrays, what kind of data can a C struct be used for storing?
Only homogeneous data (data of the same type).
Only character data.
Heterogeneous data (data of different data types).
Only integer data.
What is a pointer in C programming?
A variable that stores a numerical value.
A variable that stores the memory address of another variable as its value.
A constant that stores a fixed memory location.
A function that returns a memory address.
Which operator is used for dereferencing a pointer to indirectly access the object it references?
& (address-of operator)
. (direct member access operator)
* (indirection operator or value-at-operator).
-> (indirect member access operator)
Why is file handling necessary in C programming?
To speed up program execution only.
To ensure data is lost when the program terminates.
To preserve data even after the program terminates and to handle large amounts of data efficiently.
To display data only on the console.
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?
r+
a+
w+.
rb
When defining an enum in C like enum weekdays {Sunday, Monday, Tuesday};, what is the default integral value assigned to Sunday?
-1
0.
1
Undefined
Which preprocessor directive is used to define a macro in C?
#include
#ifndef
#define.
#undef
What operator(s) can be used to access members of a structure object?
-> (arrow operator) only.
. (dot operator) only.
Both . (dot operator) and -> (arrow operator).
& (address-of operator) only.
