Showing 191–198 of 198 questions
Consider a function declared as 'static int func()'. What is the scope of this function?
A
Global scope across all files
B
Limited to the current file only
C
Only within the function where it's declared
D
Limited to the current block
Correct Answer:
B. Limited to the current file only
EXPLANATION
When 'static' is applied to a function at file scope, it restricts the function's visibility to that translation unit (file) only.
What will be the output of the following code?
#include
int main() {
int x = 5;
int y = ++x * ++x;
printf("%d", y);
return 0;
}
A
42
B
49
C
Undefined behavior
D
Runtime Error
Correct Answer:
C. Undefined behavior
EXPLANATION
The expression ++x * ++x modifies x twice without an intervening sequence point, causing undefined behavior.
Which of the following correctly declares a function pointer?
A
int *func;
B
int (*func)();
C
int func*();
D
int *func();
Correct Answer:
B. int (*func)();
EXPLANATION
Function pointers require parentheses around the pointer name: int (*func)(). Option D declares a function returning int pointer, not a function pointer.
What is the main difference between #define and const in C?
A
#define is preprocessed while const is handled by compiler
B
const occupies memory while #define does not
C
Both A and B
D
There is no difference
Correct Answer:
C. Both A and B
EXPLANATION
#define is a preprocessor directive replaced before compilation, while const creates an actual variable. const occupies memory; #define does not.
What will be the output of the following code?
#include
int main() {
int x = 5;
printf("%d", ++x + x++);
return 0;
}
A
12
B
13
C
11
D
Undefined behavior
Correct Answer:
D. Undefined behavior
EXPLANATION
The expression ++x + x++ involves modifying x multiple times without an intervening sequence point, leading to undefined behavior in C.
Which storage class has a default value of 0 if not explicitly initialized?
A
auto
B
register
C
static
D
extern
Correct Answer:
C. static
EXPLANATION
Static variables are initialized to 0 by default. auto and register variables have garbage values if not initialized. extern variables are declared elsewhere.
Consider the expression: int arr[5]; What does arr represent without the index?
A
The first element of array
B
Base address of the array
C
Error - incomplete expression
D
The entire array as a single value
Correct Answer:
B. Base address of the array
EXPLANATION
In C, the array name arr (without index) decays to a pointer to its first element, representing the base address.
What will be the output of: int x = 10; printf("%d %d", x, x++);
A
10 10
B
10 11
C
11 10
D
Undefined behavior
Correct Answer:
D. Undefined behavior
EXPLANATION
Modifying and using a variable in the same expression without an intervening sequence point results in undefined behavior.