Question:

The size of int datatype in C++ is

Show Hint

Never assume a fixed size for \( \texttt{int} \) in C++. If you need a specific size, use the fixed-width integer types from the \( \langle \texttt{cstdint} \rangle \) header, such as \( \texttt{int32\_t} \) for a 32-bit integer.

  • 1 byte
  • 2 bytes
  • 4 bytes
  • Depends on compiler
Hide Solution
collegedunia
Verified By Collegedunia

The Correct Option is D

Solution and Explanation

Step 1: Understand the C++ standard for data types. The C++ standard does not define a fixed size for fundamental data types like `int`. It only guarantees a minimum range of values they can hold.
Step 2: Analyze the options. The actual size of an `int` depends on the compiler and the architecture of the system (e.g., 16-bit, 32-bit, or 64-bit).

On older 16-bit systems, an `int` was often 2 bytes.
On most modern 32-bit and 64-bit systems, an `int` is typically 4 bytes.
However, this is an implementation detail, not a language rule.
Therefore, the most accurate answer is that the size depends on the compiler and the underlying system.
Was this answer helpful?
0
0