Showing 21–30 of 100 questions
in Data Types & Variables
What is the output of: int a = 5, b = 2; printf("%d", a / b);
A
2.5
B
2
C
3
D
Compilation error
EXPLANATION
Both a and b are integers, so integer division is performed: 5/2 = 2 (remainder discarded).
Which data type would be most appropriate to store a person's age in a program?
A
float
B
double
C
int
D
char
EXPLANATION
Age is an integer value. Using 'int' is appropriate and memory-efficient. Floating-point types are unnecessary for this discrete value.
What will be printed: float f = 5/2; printf("%f", f);
A
2.5
B
2.000000
C
2
D
Undefined
Correct Answer:
B. 2.000000
EXPLANATION
5/2 performs integer division resulting in 2, which is then stored in float f. printf("%f") prints 2.000000 (default 6 decimal places).
What is the size of 'long long' data type in C99 standard?
A
4 bytes
B
8 bytes
C
At least 8 bytes
D
16 bytes
Correct Answer:
C. At least 8 bytes
EXPLANATION
C99 standard guarantees 'long long' to be at least 64 bits (8 bytes), but some systems may allocate more.
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.
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.
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.
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.
Which of the following statements about 'register' keyword is TRUE?
A
It guarantees variable storage in CPU register
B
It's a hint to compiler for optimization
C
It prevents taking address of variable
D
Both B and C
Correct Answer:
D. Both B and C
EXPLANATION
Register is a hint only; compiler may ignore it. You cannot use & operator on register variables.
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.