Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

499 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 411–420 of 499
Topics in C Programming
What happens when you declare a variable without initializing it in C?
A It automatically gets value 0
B It contains garbage value
C Compilation error occurs
D It remains undefined until assigned
Correct Answer:  B. It contains garbage value
EXPLANATION

Uninitialized local variables contain garbage values (whatever was in memory). Only static/global variables are zero-initialized.

Take Test
What will be printed: float f = 5/2; printf("%f", f);
A 2.5
B 2.000000
C 2
D Undefined
Correct Answer:  B. 2.000000
EXPLANATION

5/2 performs integer division resulting in 2, which is then stored in float f. printf("%f") prints 2.000000 (default 6 decimal places).

Take Test
What is the size of 'long long' data type in C99 standard?
A 4 bytes
B 8 bytes
C At least 8 bytes
D 16 bytes
Correct Answer:  C. At least 8 bytes
EXPLANATION

C99 standard guarantees 'long long' to be at least 64 bits (8 bytes), but some systems may allocate more.

Take Test
Which keyword is used to declare a variable that maintains its value between function calls?
A extern
B static
C const
D volatile
Correct Answer:  B. static
EXPLANATION

The 'static' keyword gives a variable static storage duration, preserving its value between function calls.

Take Test
What will be the output of: int x = 10; printf("%u", -x);
A -10
B 4294967286
C 10
D Compilation error
Correct Answer:  B. 4294967286
EXPLANATION

When -10 is assigned to an unsigned int format (%u), it gets interpreted as a large positive number due to two's complement representation on a 32-bit system.

Take Test
What is the behavior of 'auto' keyword in modern C (C99 onwards)?
A It makes variable automatic
B It's rarely used but still valid
C It's deprecated and causes error
D It allocates memory on heap
Correct Answer:  B. It's rarely used but still valid
EXPLANATION

In C99+, auto is rarely used since local variables are automatic by default, but it remains valid syntax.

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