All mock tests are FREE till 31 December — register to save your progress

Arrange the following data types in non-decreasing order according to the length of their representation in C++.
A. char
B. int
C. float
D. double
Choose the correct answer from the options given below:

Pick an option to check yourself, or open the answer below.

Show answer & explanation

Correct answer: D. A, B, C, D

Explanation

On a typical C++ implementation, char occupies 1 byte, int and float each occupy 4 bytes, and double occupies 8 bytes. Arranging these sizes in non-decreasing order gives char (1) ≤ int (4) = float (4) ≤ double (8), which corresponds to the sequence char, int, float, double. Any ordering that places a larger type before a smaller one, such as int before char or double before float, violates the non-decreasing requirement. So the correct order is A, B, C, D.

More Programming Languages and Computer Graphics questions