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 421–430 of 499
Topics in C Programming
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
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
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.

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

Static variables retain their values between function calls and are initialized only once, maintaining state across invocations.

Take Test
Which format specifier is used for printing a long integer?
A %d
B %ld
C %lld
D %D
Correct Answer:  B. %ld
EXPLANATION

%ld is for long int, %lld is for long long int, and %d is for regular int. Using wrong specifier can cause undefined behavior.

Take Test
What will happen if you declare a variable without initializing it?
A It will have a garbage value (undefined)
B It will be automatically initialized to 0
C Compilation error occurs
D It will be initialized to NULL
Correct Answer:  A. It will have a garbage value (undefined)
EXPLANATION

Uninitialized local variables contain garbage values (random data from memory). Static/global variables are initialized to 0 by default.

Take Test
In C, what is the result of: int x = 5.7?
A Compilation error
B x = 5 (implicit truncation)
C x = 5.7
D x = 6 (rounded)
Correct Answer:  B. x = 5 (implicit truncation)
EXPLANATION

When assigning a double to int, C performs implicit type conversion with truncation (not rounding). The decimal part is discarded.

Take Test
What is the difference between 'char' and 'unsigned char' for character representation?
A No difference; they are aliases
B char can hold negative values; unsigned char cannot
C unsigned char can hold larger ASCII values (128-255)
D Both B and C are correct
Correct Answer:  D. Both B and C are correct
EXPLANATION

char (signed) has range -128 to 127, while unsigned char has 0 to 255. The latter can represent extended ASCII characters (128-255).

Take Test
What is the output of: printf("%d", sizeof(int) + sizeof(char))?
A 4
B 5
C Depends on system (at least 3)
D 8
Correct Answer:  C. Depends on system (at least 3)
EXPLANATION

sizeof(int) is typically 4 bytes and sizeof(char) is 1 byte, giving 5 on most systems. However, sizes are implementation-dependent (at least int=2, char=1).

Take Test
What happens when you assign a larger data type value to a smaller one?
A Compilation error occurs
B Implicit type conversion (with possible data loss)
C Runtime error occurs
D The value is automatically promoted
Correct Answer:  B. Implicit type conversion (with possible data loss)
EXPLANATION

C allows implicit type conversion. When assigning larger to smaller type, truncation or data loss may occur without any compiler error.

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