C Programming — Data Types & Variables
C language from basics to advanced placement prep
29 Questions 10 Topics Take Test
Advertisement
Showing 1–10 of 29 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
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
What is the size of a 'long long int' variable in C on a 64-bit system?
A 4 bytes
B 8 bytes
C 16 bytes
D Compiler dependent
Correct Answer:  B. 8 bytes
EXPLANATION

A 'long long int' is guaranteed to be at least 64 bits (8 bytes) by the C99 standard on all systems including 64-bit architectures.

Take Test
In C programming, which of the following is NOT a fundamental data type?
A int
B float
C string
D double
Correct Answer:  C. string
EXPLANATION

string is not a fundamental data type in C. Fundamental types are int, float, double, char, and void. Strings are arrays of characters.

Take Test
Advertisement
What is the output of: int a = 5, b = 2; printf("%d", a / b);
A 2.5
B 2
C 3
D Compilation error
Correct Answer:  B. 2
EXPLANATION

Both a and b are integers, so integer division is performed: 5/2 = 2 (remainder discarded).

Take Test
Which data type would be most appropriate to store a person's age in a program?
A float
B double
C int
D char
Correct Answer:  C. int
EXPLANATION

Age is an integer value. Using 'int' is appropriate and memory-efficient. Floating-point types are unnecessary for this discrete value.

Take Test
What is the difference between 'signed' and 'unsigned' char?
A Only storage capacity differs
B Range of values they can store differs
C Signed cannot store special characters
D Unsigned uses more memory
Correct Answer:  B. Range of values they can store differs
EXPLANATION

Signed char ranges from -128 to 127, while unsigned char ranges from 0 to 255. Both use 1 byte but interpret the bits differently.

Take Test
What is the size of the 'char' data type in C on most modern systems?
A 1 byte
B 2 bytes
C 4 bytes
D 8 bytes
Correct Answer:  A. 1 byte
EXPLANATION

The 'char' data type occupies 1 byte (8 bits) of memory on virtually all modern C systems, as per the C standard.

Take Test
What happens if you assign a double value to an int variable without casting?
A Compilation error
B The fractional part is truncated
C The value is rounded
D Runtime error
Correct Answer:  B. The fractional part is truncated
EXPLANATION

Implicit conversion truncates decimal part. int x = 3.7; results in x=3 with no 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