C Data Types Quiz - MCQ Questions and Answers

1. Which of the following is not a basic data type in C?

a) int
b) float
c) string
d) char

Answer:

c) string

Explanation:

In C, 'string' is not a basic data type. Strings are typically represented as arrays of characters.

2. What is the size of 'int' on a standard 32-bit system in C?

a) 2 bytes
b) 4 bytes
c) 8 bytes
d) Depends on the compiler

Answer:

b) 4 bytes

Explanation:

On a standard 32-bit system, 'int' usually occupies 4 bytes.

3. Which data type would you use to store a character in C?

a) int
b) char
c) float
d) bool

Answer:

b) char

Explanation:

The 'char' data type is used to store a single character in C.

4. What is the range of values for an unsigned char data type in C?

a) -128 to 127
b) 0 to 255
c) -255 to 255
d) 0 to 127

Answer:

b) 0 to 255

Explanation:

An unsigned char has a range of 0 to 255, as it does not store negative values.

5. How is a floating-point number declared in C?

a) using the 'float' keyword
b) using the 'double' keyword
c) using the 'long double' keyword
d) any of the above

Answer:

d) any of the above

Explanation:

Floating-point numbers in C can be declared using 'float', 'double', or 'long double', depending on the required precision.

6. What is the size of a 'double' data type in C on a typical 64-bit system?

a) 4 bytes
b) 8 bytes
c) 16 bytes
d) Depends on the compiler

Answer:

b) 8 bytes

Explanation:

On a typical 64-bit system, the size of a 'double' is 8 bytes, but it can vary depending on the compiler and system architecture.

7. Which of the following data types is most suitable for storing a large integer, such as 10000000000, in C?

a) int
b) unsigned int
c) long
d) float

Answer:

c) long

Explanation:

The 'long' data type is suitable for storing larger integers. 'int' and 'unsigned int' may not be able to store such large values.

8. Which data type would be best to use for a variable that stores values -1, 0, and 1 in C?

a) char
b) int
c) unsigned int
d) float

Answer:

b) int

Explanation:

The 'int' data type is suitable for storing these values, as it can hold both negative and positive integers.

9. What is the size of the 'long long int' data type in C on most systems?

a) 4 bytes
b) 8 bytes
c) 16 bytes
d) Varies with the system

Answer:

b) 8 bytes

Explanation:

On most systems, 'long long int' is 8 bytes, but this can vary with different system architectures.

10. In C, which of the following data types has the highest precision for storing decimal numbers?

a) float
b) double
c) long double
d) All have the same precision

Answer:

c) long double

Explanation:

'long double' has the highest precision among floating-point data types in C.

11. Which keyword is used to define a boolean data type in C?

a) bool
b) boolean
c) _Bool
d) bit

Answer:

a) bool

Explanation:

The 'bool' keyword, which is defined in the 'stdbool.h' header, represents boolean values in C.

12. What is the output of the following C code?

   printf("%lu", sizeof(float));
a) 2
b) 4
c) 8
d) The output depends on the system

Answer:

b) 4

Explanation:

Typically, the size of 'float' in C is 4 bytes. However, it can vary depending on the system.

13. Which of the following is not a valid integer data type in C?

a) short
b) long
c) byte
d) int

Answer:

c) byte

Explanation:

In C, 'byte' is not a valid integer data type. The valid integer types are 'short', 'int', and 'long'.

14. What is the default type for a floating-point constant in C?

a) float
b) double
c) long double
d) None of the above

Answer:

b) double

Explanation:

In C, a floating-point constant without a suffix is considered a 'double'.

15. Which data type is used for storing a single byte in C?

a) char
b) int
c) byte
d) short

Answer:

a) char

Explanation:

The 'char' data type in C is used to store a single byte of data.

16. What will be the range of a signed char data type in C?

a) -128 to 127
b) 0 to 255
c) -255 to 255
d) -127 to 128

Answer:

a) -128 to 127

Explanation:

A signed char can hold values from -128 to 127.

17. How many bytes are allocated for a 'short int' data type in C?

a) 1
b) 2
c) 4
d) Depends on the system

Answer:

b) 2

Explanation:

A 'short int' typically occupies 2 bytes in C, though this may vary with different system architectures.

18. What is the size of the 'long int' data type in C on a standard 32-bit system?

a) 2 bytes
b) 4 bytes
c) 8 bytes
d) Varies with the system

Answer:

b) 4 bytes

Explanation:

On a standard 32-bit system, the size of a 'long int' is generally 4 bytes.

19. What does the 'unsigned' modifier do to an integer data type in C?

a) Increases its size
b) Allows it to store negative values
c) Prevents it from storing negative values
d) Has no effect

Answer:

c) Prevents it from storing negative values

Explanation:

The 'unsigned' modifier means the integer variable can only store non-negative values.

20. What is the output of the following C code snippet?

printf("%zu", sizeof(double));
a) 4
b) 6
c) 8
d) Depends on the system

Answer:

c) 8

Explanation:

Typically, the size of 'double' in C is 8 bytes, though this can vary depending on the system.

21. What data type should be used for a variable that needs to store very large floating-point numbers in C?

a) float
b) double
c) long double
d) long

Answer:

c) long double

Explanation:

'long double' is the most suitable for storing very large floating-point numbers due to its higher precision and range.

22. In C, what will be the size of a pointer variable on a 64-bit system?

a) 4 bytes
b) 8 bytes
c) Depends on the data type it points to
d) 16 bytes

Answer:

b) 8 bytes

Explanation:

On a 64-bit system, a pointer variable typically occupies 8 bytes, regardless of the data type it points to.

23. Which data type is best suited for storing ASCII values in C?

a) int
b) char
c) unsigned char
d) short

Answer:

b) char

Explanation:

The 'char' data type is best suited for storing ASCII values, as each ASCII character is represented by a single byte.

24. What will be the range of an 'unsigned int' data type in C?

a) 0 to 4294967295
b) -2147483648 to 2147483647
c) -4294967295 to 4294967295
d) 0 to 65535

Answer:

a) 0 to 4294967295

Explanation:

An 'unsigned int' in C typically has a range from 0 to 4294967295 on a 32-bit system.

25. What is the size of a 'wchar_t' data type in C?

a) 1 byte
b) 2 bytes
c) 4 bytes
d) Depends on the compiler

Answer:

d) Depends on the compiler

Explanation:

The size of 'wchar_t' varies depending on the compiler and the system. It is typically 2 or 4 bytes.

Comments