Home Subjects C Programming Data Types & Variables

C Programming
Data Types & Variables

C language from basics to advanced placement prep

17 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 11–17 of 17
Topics in C Programming
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.

Test
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.

Test
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.

Test
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.

Test
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
Correct Answer:  A. 5
EXPLANATION

q is a pointer to pointer p. **q dereferences both pointers, giving the value of a, which is 5.

Test
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.

Test
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.

Test
IGET
IGET AI
Online · Exam prep assistant
Hi! 👋 I'm your iget AI assistant.

Ask me anything about exam prep, MCQ solutions, study tips, or strategies! 🎯
UPSC strategy SSC CGL syllabus Improve aptitude NEET Biology tips