Showing 171–180 of 198 questions
In the declaration 'int *p, q;', what are the data types?
A
p is int, q is pointer to int
B
p is pointer to int, q is int
C
Both are pointers to int
D
Both are integers
Correct Answer:
B. p is pointer to int, q is int
EXPLANATION
The '*' applies only to the immediately following variable. So 'int *p' declares p as pointer to int, and 'q' is just an int.
In the declaration 'volatile int x;', what does volatile signify?
A
x can be changed by external factors unexpectedly
B
x cannot be modified after initialization
C
x is stored in CPU register for faster access
D
x is a temporary variable
Correct Answer:
A. x can be changed by external factors unexpectedly
EXPLANATION
volatile tells the compiler that the variable's value may change unexpectedly (e.g., by hardware, signals, or another thread), so the compiler should not optimize it.
Which of the following statements about type qualifiers is INCORRECT?
A
const prevents modification after initialization
B
volatile prevents compiler optimization
C
restrict allows pointer aliasing
D
restrict is a C99 feature
Correct Answer:
C. restrict allows pointer aliasing
EXPLANATION
restrict prevents pointer aliasing (not allows). It tells compiler that pointer is the only way to access that object.
Consider a structure with int (4 bytes), char (1 byte), and double (8 bytes). What is the minimum size due to alignment requirements?
A
13 bytes
B
16 bytes
C
24 bytes
D
20 bytes
Correct Answer:
C. 24 bytes
EXPLANATION
Due to structure padding/alignment, the size becomes 24 bytes (8-byte alignment for double). Members are padded to maintain alignment.
What is true about the variable declared as 'extern int count;' inside a function?
A
It declares a new local variable
B
It refers to a global variable defined elsewhere
C
It creates a static variable
D
It's a compilation error
Correct Answer:
B. It refers to a global variable defined elsewhere
EXPLANATION
extern is a declaration (not definition) that tells compiler the variable exists elsewhere in program. It provides global scope.
What is the output of the following code?
int a = 5;
int *p = &a;
int **q = &p;
printf("%d", **q);
A
5
B
Address of a
C
Address of p
D
Compilation error
EXPLANATION
q is a pointer to pointer p. **q dereferences both pointers, giving the value of a, which is 5.
What is the purpose of the 'volatile' keyword in C?
A
To prevent variable modification
B
To tell compiler not to optimize access to a variable
C
To allocate memory on stack
D
To make variable globally accessible
Correct Answer:
B. To tell compiler not to optimize access to a variable
EXPLANATION
'volatile' tells the compiler that a variable's value may change unexpectedly (e.g., by hardware), preventing optimization.
Which of the following correctly demonstrates pointer arithmetic?
A
int *p; p++;
B
int x = 5; x++;
C
char c = 'a'; c = c + 1;
D
float f = 3.14; f = f + 1;
Correct Answer:
A. int *p; p++;
EXPLANATION
Option A shows pointer arithmetic where p++ increments the pointer by the size of int (4 bytes). Other options are regular arithmetic operations.
What will be the size of the following structure?
struct test {
char c;
int i;
float f;
};
A
9 bytes
B
12 bytes
C
13 bytes
D
Depends on padding and alignment
Correct Answer:
D. Depends on padding and alignment
EXPLANATION
Size depends on compiler's padding and alignment rules. Typically 12 bytes with padding, but varies by system.
Consider the following declaration:
int (*func_ptr)(int, int, int);
Which of the following function signatures can be correctly assigned to func_ptr?
A
int add(int x, int y, int z) { return x+y+z; }
B
int add(int x, int y) { return x+y; }
C
void add(int x, int y, int z) { }
D
float add(int x, int y, int z) { return x+y+z; }
Correct Answer:
A. int add(int x, int y, int z) { return x+y+z; }
EXPLANATION
func_ptr must point to a function that takes exactly 3 int parameters and returns int. Only option A matches this signature exactly.