C Programming — Data Types & Variables
C language from basics to advanced placement prep
100 Questions 10 Topics Take Test
Advertisement
Showing 1–10 of 100 questions in Data Types & Variables
In C programming, when you declare a variable as 'const int x = 5;', what happens if you try to modify it within the program?
A The compiler will generate a warning but allow modification at runtime
B The compiler will generate a compilation error and prevent modification
C The variable will be modified but will revert to original value after each operation
D The modification will be allowed only in the main() function
Correct Answer:  B. The compiler will generate a compilation error and prevent modification
EXPLANATION

The 'const' keyword creates a read-only variable. Once initialized, attempting to modify a const variable results in a compilation error (error: assignment of read-only variable). This is enforced at compile-time, not runtime.

Take Test
What happens when a volatile variable is declared in a multi-threaded C program?
A It becomes thread-safe automatically
B Compiler won't optimize it away and will fetch value from memory each time
C It can only be accessed by one thread
D It doubles in size for redundancy
Correct Answer:  B. Compiler won't optimize it away and will fetch value from memory each time
EXPLANATION

volatile tells compiler not to optimize variable accesses and to fetch fresh value from memory, useful for hardware registers and shared memory, but doesn't guarantee thread-safety without synchronization.

Take Test
Consider a scenario where you need to store a variable that can hold values up to 10 billion. Which data type is most suitable?
A int
B long int
C long long int
D float
Correct Answer:  C. long long int
EXPLANATION

int max is ~2.1 billion, long int varies (may be 32 or 64 bits). long long int guarantees 64 bits with max ~9.2 quintillion, sufficient for 10 billion.

Take Test
What is the output of:
int arr[3] = {1, 2, 3};
int *p = arr;
printf("%d %d", *p, *(p+2));
A 1 3
B 1 2
C 3 3
D Garbage values
Correct Answer:  A. 1 3
EXPLANATION

p points to arr[0] which is 1. p+2 points to arr[2] which is 3. Therefore output is '1 3'.

Take Test
Which storage class has both 'static' and 'auto' properties in certain contexts?
A register
B extern
C static
D volatile
Correct Answer:  A. register
EXPLANATION

register requests compiler to store variable in CPU register for faster access but falls back to memory if unavailable, combining automatic allocation with optimization hints.

Take Test
Advertisement
What will be the result of the following expression:
float x = 0.1 + 0.2;
if(x == 0.3) printf("Equal"); else printf("Not Equal");
A Equal
B Not Equal
C Undefined behavior
D Compilation error
Correct Answer:  B. Not Equal
EXPLANATION

Due to floating-point precision limitations, 0.1 + 0.2 does not exactly equal 0.3 in binary representation. Direct comparison with == fails.

Take Test
In C, what is the difference between 'int' and 'unsigned int' in terms of range on a 32-bit system?
A unsigned int has double the maximum value
B int ranges from -2^31 to 2^31-1, unsigned int from 0 to 2^32-1
C They have identical ranges
D unsigned int ranges from -2^32 to 2^32
Correct Answer:  B. int ranges from -2^31 to 2^31-1, unsigned int from 0 to 2^32-1
EXPLANATION

signed int reserves 1 bit for sign, giving range -2147483648 to 2147483647. unsigned int uses all 32 bits for magnitude, giving 0 to 4294967295.

Take Test
What is the output of the following code:
int a = 5;
int *p = &a;
int **q = &p;
printf("%d", **q);
A 5
B Address of a
C Address of p
D Compilation error
Correct Answer:  A. 5
EXPLANATION

q is a pointer to pointer p. *q dereferences q to get p, and **q dereferences p to get the value of a, which is 5.

Take Test
Which of the following variable declarations will occupy the LEAST memory?
A unsigned int x;
B float y;
C char z;
D double w;
Correct Answer:  C. char z;
EXPLANATION

char data type typically occupies 1 byte, which is the minimum. int is 4 bytes, float is 4 bytes, and double is 8 bytes on most systems.

Take Test
Which keyword is used to declare a variable that cannot be modified after initialization?
A static
B volatile
C const
D extern
Correct Answer:  C. const
EXPLANATION

The 'const' keyword declares a constant variable whose value cannot be modified after initialization. Attempting to modify it results in a compile-time 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