C++ Data Types MCQ

In the realm of programming, data types play an indispensable role. They determine the kind of data that a variable can hold and how much memory it will occupy. C++ offers a rich set of built-in data types, each designed for specific purposes. Are you up for a challenge? Test your understanding of C++ data types with this beginner’s quiz!

1. Which data type is used to store a single character in C++?

a) char
b) str
c) text
d) character

Answer:

a) char

Explanation:

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

2. What will be the size of int in a typical 32-bit architecture?

a) 2 bytes
b) 4 bytes
c) 8 bytes
d) It varies

Answer:

b) 4 bytes

Explanation:

In a typical 32-bit architecture, the size of int is 4 bytes.

3. Which of the following is a floating-point data type in C++?

a) double
b) long
c) short
d) boolean

Answer:

a) double

Explanation:

double is a floating-point data type in C++.

4. Which data type can store both true and false values?

a) bool
b) binary
c) bit
d) tf

Answer:

a) bool

Explanation:

The bool data type is used to store Boolean values, which can be either true or false.

5. How many bytes does the long long int typically occupy?

a) 4 bytes
b) 6 bytes
c) 8 bytes
d) 10 bytes

Answer:

c) 8 bytes

Explanation:

Typically, long long int occupies 8 bytes of memory.

6. Which of the following data types does not have a signed and unsigned variant?

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

Answer:

b) bool

Explanation:

The bool data type does not have signed and unsigned variants. It can only hold true or false values.

7. Which of the following is not a standard C++ data type?

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

Answer:

c) string

Explanation:

Although string is commonly used in C++, it is not a fundamental data type. It is a class provided by the C++ Standard Library.

8. What is the range of values for an unsigned char?

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 can hold values from 0 to 255.

9. Which of the following is the correct way to declare a floating-point variable in C++?

a) float x = 10.5
b) int x = 10.5
c) decimal x = 10.5
d) number x = 10.5

Answer:

a) float x = 10.5

Explanation:

The float data type is used for floating-point values, so the correct declaration is float x = 10.5.

10. Which data type would be most suitable for storing the age of a person?

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

Answer:

d) int

Explanation:

Age is typically represented as a whole number, making int the most appropriate data type for this purpose.

Congratulations on attempting the C++ Data Types quiz! Data types are fundamental to programming, as they dictate what kind of data we can work with and how operations will behave. Whether you’re just getting started or brushing up, it’s always good to challenge yourself and revisit the basics. Keep coding and keep learning!


Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top