Home Subjects C Programming

C Programming

C language from basics to advanced placement prep

1,000 Q 10 Topics Take Test
Advertisement
Difficulty: All Easy Medium Hard 841–850 of 1,000
Topics in C Programming
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
What is the range of 'signed char' in C?
A 0 to 255
B -128 to 127
C -256 to 255
D 0 to 127
Correct Answer:  B. -128 to 127
EXPLANATION

Signed char uses 8 bits with one bit for sign, giving range -128 to 127 (2^7 to 2^7-1).

Take Test
What is the size of a 'float' data type in C on most 32-bit systems?
A 2 bytes
B 4 bytes
C 8 bytes
D 16 bytes
Correct Answer:  B. 4 bytes
EXPLANATION

On most 32-bit systems, float occupies 4 bytes (32 bits) of memory according to IEEE 754 standard.

Take Test
What is the purpose of the 'restrict' keyword in modern C?
A To prevent a variable from being modified
B To tell the compiler that a pointer has exclusive access to data
C To limit variable scope
D To make variable read-only
Correct Answer:  B. To tell the compiler that a pointer has exclusive access to data
EXPLANATION

restrict (C99) informs the compiler that a pointer is the sole accessor to the object, enabling optimization. It doesn't prevent modification.

Take Test
In the declaration 'int *p, q;', what are the data types?
A p is int, q is pointer to int
B p is pointer to int, q is int
C Both are pointers to int
D Both are integers
Correct Answer:  B. p is pointer to int, q is int
EXPLANATION

The '*' applies only to the immediately following variable. So 'int *p' declares p as pointer to int, and 'q' is just an int.

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
What is the difference between initialization and assignment in C?
A Both terms mean the same thing
B Initialization happens at declaration; assignment happens later
C Assignment happens during declaration; initialization happens later
D Initialization is for arrays; assignment is for variables
Correct Answer:  B. Initialization happens at declaration; assignment happens later
EXPLANATION

Initialization assigns a value when the variable is declared (int x = 5;). Assignment changes the value later (x = 10;).

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