Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

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

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.

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.

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

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.

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

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.

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.

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.

Test
What is the output of the following code?
int x = 10;
int *p = &x;
printf("%d", *p + 5);
A 10
B 15
C 5
D Compilation error
Correct Answer:  B. 15
EXPLANATION

*p dereferences pointer to get value 10, then 10+5=15 is printed.

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