Home Subjects C Programming Data Types & Variables

C Programming
Data Types & Variables

C language from basics to advanced placement prep

100 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 31–40 of 100
Topics in C Programming
What is the result of: printf("%d", (int)(3.9) + 0.5);?
A 3
B 4
C 3.5
D Compilation error
Correct Answer:  A. 3
EXPLANATION

(int)(3.9) = 3, then 3 + 0.5 = 3.5, but %d prints as int 3 (truncated).

Take Test
Which variable declaration uses automatic storage duration?
A static int x;
B extern int x;
C int x; (inside function)
D int x; (at global scope)
Correct Answer:  C. int x; (inside function)
EXPLANATION

Local variables declared inside functions have automatic storage duration and are destroyed on function exit.

Take Test
What is the purpose of the 'volatile' keyword?
A To prevent variable modification
B To inform compiler that value may change unexpectedly
C To make variable static
D To optimize memory usage
Correct Answer:  B. To inform compiler that value may change unexpectedly
EXPLANATION

Volatile prevents compiler optimizations by signaling the variable may change outside program control (hardware/signals).

Take Test
What happens if you assign a double value to an int variable without casting?
A Compilation error
B The fractional part is truncated
C The value is rounded
D Runtime error
Correct Answer:  B. The fractional part is truncated
EXPLANATION

Implicit conversion truncates decimal part. int x = 3.7; results in x=3 with no error.

Take Test
Which of the following correctly declares a constant pointer to a constant integer?
A const int * const p;
B int const * const p;
C const int const * p;
D Both A and B
Correct Answer:  D. Both A and B
EXPLANATION

Both 'const int * const p' and 'int const * const p' are equivalent and declare constant pointer to constant integer.

Take Test
What is printed by: int x = 5; printf("%d %d", x++, ++x);?
A 5 7
B 6 7
C Undefined behavior
D 7 7
Correct Answer:  C. Undefined behavior
EXPLANATION

Modifying variable x twice without intervening sequence point causes undefined behavior.

Take Test
Which storage class has global scope and external linkage by default?
A auto
B static
C extern
D register
Correct Answer:  C. extern
EXPLANATION

Global variables with extern keyword have global scope and external linkage across translation units.

Take Test
What will be the output of: printf("%ld", sizeof(long double));
A 4
B 8
C 12 or 16
D Depends on compiler
Correct Answer:  D. Depends on compiler
EXPLANATION

Size of long double varies: typically 12 or 16 bytes on different systems and compilers.

Take Test
What is the difference between 'const int *p' and 'int * const p'?
A No difference
B First allows changing pointer, second allows changing value
C First prevents changing value, second prevents changing pointer
D Both prevent all modifications
Correct Answer:  C. First prevents changing value, second prevents changing pointer
EXPLANATION

'const int *p' - pointer can change but value cannot. 'int * const p' - value can change but pointer cannot.

Take Test
Which of the following declarations allocates memory for a variable?
A extern int x;
B int x;
C static int x;
D Both B and C
Correct Answer:  D. Both B and C
EXPLANATION

Both 'int x;' and 'static int x;' allocate memory. Extern only declares without allocation.

Take Test
IGET
iget AI
Online · Ask anything about exams
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