Data types are integral to C programming. They help in classifying the type of data, ensuring proper memory allocation, and enabling appropriate operations on the data. This quiz is designed for beginners to test their understanding of the fundamental data types in C. Let’s jump right in!
Note that each question is followed by the correct answer and an explanation to help reinforce your knowledge.
1. Which of the following is a derived data type in C?
Answer:
Explanation:
Arrays are derived data types in C, created using fundamental types like int, char, etc.
2. What is the size (in bytes) of double on most modern systems?
Answer:
Explanation:
On most systems, a double is 8 bytes. But it’s always good to check using the sizeof() operator for platform-specific sizes.
3. What data type is best suited for storing a single character?
Answer:
Explanation:
The char data type is specifically designed for storing a single character.
4. Which of the following is a non-standard integer type?
Answer:
Explanation:
byte is not a standard integer type in C.
5. How many bytes does the int data type usually occupy?
Answer:
Explanation:
Typically, in most modern systems, an int occupies 4 bytes (32 bits), but this can vary depending on the system and compiler.
6. Which of the following types can store a larger range of integers?
Answer:
Explanation:
long long can typically store larger integers compared to the other listed types.
7. Which data type in C has only two possible values?
Answer:
Explanation:
The _Bool (or bool with stdbool.h included) can have only two values: true or false.
8. Which of the following is not a floating-point data type?
Answer:
Explanation:
long int is an integer type, not a floating-point type.
9. Which type is used to store a wide character in C?
Answer:
Explanation:
wchar_t is used for wide characters.
10. If a variable is declared as unsigned short int, what is its typical size on modern systems?
Answer:
Explanation:
Typically, an unsigned short int occupies 2 bytes on modern systems.
11. Which of the following data types has the smallest storage size?
Answer:
Explanation:
Typically, a char occupies 1 byte, making it smaller than the other listed data types.
12. What would be the outcome of sizeof(_Bool) in C?
Answer:
Explanation:
The _Bool type, or bool when including stdbool.h, typically occupies 1 byte.
13. What is the primary difference between int and unsigned int?
Answer:
Explanation:
Both int and unsigned int typically occupy the same memory, but unsigned int can’t store negative values, extending its positive range.
14. Which data type would be most suitable for storing the value of PI (3.14159…)?
Answer:
Explanation:
double provides more precision than float, making it more suitable for storing the value of PI.
15. Which data type is used to store a sequence of characters?
Answer:
Explanation:
In C, a sequence of characters (a string) is stored as an array of char, i.e., char[].