Which of the following is a valid variable name in C?
Answer: B
Variable names in C must start with a letter or underscore, not a digit. _variable is valid. '2var' starts with digit, 'var-name' contains hyphen (invalid), 'var name' contains space (invalid).
Q.22Easy
What is the return type of the strlen() function?
Answer: C
The strlen() function returns the length of a string as an int value, representing the number of characters.
Q.23Easy
Which operator has the highest precedence in C?
Answer: C
Parentheses () have the highest precedence among all operators in C. They are always evaluated first in any expression.
Q.24Medium
In C, a pointer variable stores which of the following?
Answer: B
A pointer is a variable that stores the memory address of another variable. It is declared using the * symbol.
Q.25Medium
What is the purpose of the malloc() function in C?
Answer: B
malloc() (memory allocation) allocates a block of memory dynamically during program execution and returns a pointer to it.
Advertisement
Q.26Medium
Which of the following correctly initializes an array of 5 integers?
Answer: A
Arrays in C are declared with square brackets containing the size, followed by initialization in curly braces. Option A is the correct syntax.
Q.27Medium
What is the default return type of a function in C if not explicitly specified?
Answer: B
In C, if a function's return type is not explicitly specified, it defaults to int. However, modern C standards require explicit return type declaration.
Q.28Medium
What does the break statement do in a loop?
Answer: B
The break statement immediately terminates the loop and transfers control to the statement following the loop.
Q.29Medium
Which of the following is used to access members of a structure using a pointer?
Answer: B
The arrow operator (->) is used to access structure members through a pointer. The dot operator (.) is used for direct access.
Q.30Medium
In C, what is the purpose of the #define directive?
Answer: B
#define is a preprocessor directive used to define symbolic constants (macros) and performs text substitution before compilation.
Q.31Medium
What is the correct way to declare a function that takes no parameters and returns an integer?
Answer: B
To explicitly declare a function with no parameters in C, use 'void' as the parameter. int func(); is ambiguous in older C standards.
Q.32Hard
What will be the output of: int x = 5; printf("%d", ++x);?
Answer: B
The pre-increment operator (++x) increments x from 5 to 6 before using its value in printf(). So the output is 6.
Q.33Hard
Consider a pointer ptr pointing to an integer array. What does ptr[2] represent?
Answer: B
ptr[2] is equivalent to *(ptr+2), which dereferences the pointer and returns the value at the third element (index 2).
Q.34Hard
What is the time complexity of searching for an element in an unsorted array using linear search?
Answer: C
Linear search checks each element sequentially. In the worst case, it needs to check all n elements, resulting in O(n) time complexity.
Q.35Hard
What will be the result of executing: int a = 5, b = 10; int *ptr = &a; ptr = &b; printf("%d", *ptr);?
Answer: B
ptr is reassigned to point to b. When we dereference ptr using *ptr, we get the value stored at b, which is 10.
Q.36Hard
Which of the following statements about static variables is TRUE?
Answer: B
Static variables are initialized only once and retain their value throughout the program execution. Their value persists between function calls.
Q.37Easy
What is the size of an integer variable in most modern C compilers?
Answer: B
On most modern 32-bit and 64-bit systems, an int is typically 4 bytes (32 bits). However, the exact size can vary depending on the compiler and system architecture.
Q.38Easy
Which of the following is NOT a valid C data type?
Answer: B
C does not have a built-in boolean data type. The other options (float, double, char) are all valid primitive data types in C. Boolean functionality is typically implemented using int (0 for false, non-zero for true).
Q.39Easy
What is the purpose of the & operator in C?
Answer: C
The & operator has two uses in C: (1) When used before a variable, it returns the memory address of that variable (address-of operator), and (2) When used between two integers, it performs a bitwise AND operation.
Q.40Easy
Which keyword is used to create a constant variable in C?
Answer: C
The const keyword is used in C to declare a constant variable whose value cannot be modified after initialization. Variables declared as const are read-only.