Showing 21–30 of 200 questions
in C Programming
Which of the following is a valid variable name in C?
A
2var
B
_variable
C
var-name
D
var name
Correct Answer:
B. _variable
Explanation:
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).
What is the return type of the strlen() function?
A
void
B
char
C
int
D
float
Explanation:
The strlen() function returns the length of a string as an int value, representing the number of characters.
Which operator has the highest precedence in C?
A
Addition (+)
B
Multiplication (*)
C
Parentheses ()
D
Logical AND (&&)
Correct Answer:
C. Parentheses ()
Explanation:
Parentheses () have the highest precedence among all operators in C. They are always evaluated first in any expression.
Q.24
Medium
C Programming
In C, a pointer variable stores which of the following?
A
The actual value of a variable
B
The memory address of a variable
C
The size of a variable
D
The data type of a variable
Correct Answer:
B. The memory address of a variable
Explanation:
A pointer is a variable that stores the memory address of another variable. It is declared using the * symbol.
Q.25
Medium
C Programming
What is the purpose of the malloc() function in C?
A
To deallocate memory
B
To allocate memory dynamically at runtime
C
To initialize variables
D
To declare arrays
Correct Answer:
B. To allocate memory dynamically at runtime
Explanation:
malloc() (memory allocation) allocates a block of memory dynamically during program execution and returns a pointer to it.
Q.26
Medium
C Programming
Which of the following correctly initializes an array of 5 integers?
A
int arr[5] = {1, 2, 3, 4, 5};
B
int arr(5) = {1, 2, 3, 4, 5};
C
int [5] arr = {1, 2, 3, 4, 5};
D
int arr[5];
Correct Answer:
A. int arr[5] = {1, 2, 3, 4, 5};
Explanation:
Arrays in C are declared with square brackets containing the size, followed by initialization in curly braces. Option A is the correct syntax.
Q.27
Medium
C Programming
What is the default return type of a function in C if not explicitly specified?
A
void
B
int
C
char
D
float
Explanation:
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.28
Medium
C Programming
What does the break statement do in a loop?
A
Skips the current iteration
B
Terminates the loop immediately
C
Pauses the loop
D
Restarts the loop
Correct Answer:
B. Terminates the loop immediately
Explanation:
The break statement immediately terminates the loop and transfers control to the statement following the loop.
Q.29
Medium
C Programming
Which of the following is used to access members of a structure using a pointer?
A
Dot operator (.)
B
Arrow operator (->)
C
Ampersand (&)
D
Asterisk (*)
Correct Answer:
B. Arrow operator (->)
Explanation:
The arrow operator (->) is used to access structure members through a pointer. The dot operator (.) is used for direct access.
Q.30
Medium
C Programming
In C, what is the purpose of the #define directive?
A
To define functions
B
To define macros or constants
C
To declare variables
D
To include header files
Correct Answer:
B. To define macros or constants
Explanation:
#define is a preprocessor directive used to define symbolic constants (macros) and performs text substitution before compilation.