Home Subjects C Programming Data Types & Variables

C Programming
Data Types & Variables

C language from basics to advanced placement prep

52 Q 10 Topics Take Mock Test
Advertisement
Difficulty: All Easy Medium Hard 1–10 of 52
Topics in C Programming
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.

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

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.

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.

Test
Which of the following is a valid declaration of a constant array?
A const int arr[5] = {1,2,3,4,5};
B int const arr[5];
C const int arr[];
D Both A and B
Correct Answer:  D. Both A and B
EXPLANATION

Both declarations make the array elements constant. Option A initializes the array, while B declares it without initialization (valid at global scope).

Test
What is the range of values for a signed short int?
A -128 to 127
B -32768 to 32767
C -2147483648 to 2147483647
D 0 to 65535
Correct Answer:  B. -32768 to 32767
EXPLANATION

Signed short int is typically 2 bytes (16 bits), providing a range from -2^15 to 2^15-1.

Test
Which of these correctly represents a floating-point literal with exponent notation?
A 1.5e2
B 1.5e
C 1e2.5
D e1.5
Correct Answer:  A. 1.5e2
EXPLANATION

Correct exponent notation requires a digit before and after 'e'. 1.5e2 represents 1.5 × 10² = 150.0

Test
What will be the output: const int x = 10; x = 20; printf("%d", x);
A 10
B 20
C Compilation error
D Runtime error
Correct Answer:  C. Compilation error
EXPLANATION

const variables cannot be modified after initialization. Attempting to assign a new value causes a compilation error.

Test
Which storage class specifier limits a variable's scope to the current file?
A extern
B static
C register
D auto
Correct Answer:  B. static
EXPLANATION

The 'static' keyword, when used at file scope, restricts the variable's visibility to that file only (internal linkage).

Test
What happens when you declare a variable without initializing it in C?
A It automatically gets value 0
B It contains garbage value
C Compilation error occurs
D It remains undefined until assigned
Correct Answer:  B. It contains garbage value
EXPLANATION

Uninitialized local variables contain garbage values (whatever was in memory). Only static/global variables are zero-initialized.

Test
IGET
IGET AI
Online · Exam prep assistant
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