• Save

Modifiers & Datatypes in C++

Hello Readers,

In the previous tutorial, we discussed the variables in C++. Today, we’ll discuss the datatypes and modifiers in C++. Datatypes are used to define the type of variables and contents used. Data types are of two types:

  • Built-in datatypes
  • User-defined or abstract datatypes

Here is the official documentation if you wanna look at it. But, the problem with this is, it is a little bit confusing. Here, we have presented a complete, accurate & concise knowledge of the modifiers and datatypes in C++.

Built-in datatype

These are the datatypes that are predefined and are used directly in the program. For eg: intchar, etc.

Basic built-in datatypes in C++

These are the types, that user creates as a class or a structure. In C++ there are classes, whereas in C language user-defined datatypes are implemented as structures.

charfor char storage (1 byte)
intfor integral numbers (2 bytes)
floatfor single-precision floating-point (4 bytes)
doubledouble-precision floating-point numbers (8 bytes)

Example:

char a = 'A';          // character type
int a = 1;             // integer type
float a = 3.14234;     // floating point type 
double b = 6e-4;       // double type (e is for exponential)

Related:

User defined or Abstract data types

These are the types, that user creates as a class or a structure. In C++ there are classes, whereas in C language user-defined datatypes are implemented as structures.

Modifiers in C++

In C++, special keywords (called modifiers) can be used to modify/change the meaning of the predefined built-in data types and expand them to a much larger set. There are four datatype modifiers in C++ :

  1. long
  2. short
  3. signed
  4. unsigned

The above-mentioned modifiers can be used along with built-in datatypes to make them more precise and even expand or decrease their range.

Below mentioned are some important points about the modifiers:

  • long and short increase or decrease the maximum and minimum values that a data type will hold.
  • A plain ‘int’ must have a minimum size of that of short.
  • Size hierarchy of int  : short int < int < long int
  • Size hierarchy for floating  numbers is : float < double < long double
  • long float is not a legal type and there are no short floating point numbers in C++ language nor in C language.
  • Signed types is the default type which includes both positive and negative numbers.
  • Unsigned numbers are the numbers those are without any sign, that is always positive.

So, this is all about the datatypes in C++. If you have any doubts you can post in the comment section, or you can always mail at cpptopics@techoutflow.com. In the next tutorial, we’ll see the operators in C++. The next tutorial will be published soon.

Till then, stay tuned.

Leave a Reply

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

Share via
Copy link
Powered by Social Snap