Showing 11–20 of 150 questions
Q.11
Medium
C Programming
Which of the following correctly describes the scope of a static variable declared inside a function?
A
Local to the function, retains value between function calls
B
Global scope, initialized once
C
Local to the file only
D
Creates a new instance on each function call
Correct Answer:
A. Local to the function, retains value between function calls
Explanation:
A static variable declared inside a function has local scope (visible only within that function) but persists for the entire program lifetime. Its value is retained between function calls and is initialized only once.
Q.12
Medium
C Programming
What will be the output of the following C code?
int x = 10;
int y = 20;
int z = x < y ? x++ : y++;
printf("%d %d %d", x, y, z);
A
10 20 10
B
11 20 10
C
10 21 20
D
11 21 10
Correct Answer:
B. 11 20 10
Explanation:
Step 1: Evaluate condition x < y → 10 < 20 → true. Step 2: Execute true branch: x++ returns 10, then x becomes 11. Step 3: z = 10. Step 4: printf prints x=11, y=20, z=10.
Q.13
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.14
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.15
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.16
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.17
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.18
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.19
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.
Q.20
Medium
C Programming
What is the correct way to declare a function that takes no parameters and returns an integer?
A
int func();
B
int func(void);
C
func() returns int;
D
int func(no parameters);
Correct Answer:
B. int func(void);
Explanation:
To explicitly declare a function with no parameters in C, use 'void' as the parameter. int func(); is ambiguous in older C standards.