Fundamental data types in C++ - Data Types in C++ Full Explained Notes

Fundamental data types in C++ Data Types in  C++ - Types of Data in C++ - Fundamental data types in C++ full explained notes...



Fundamental data types in C++

 

Fundamental data types in C++

Fundamental data types in C++:

While programming, we store the variables in computer’s memory, but the computers have to know that what kind of data we want to store in them. Data types tells the compiler that what type of data, it means integer, character or floating point data type etc. the variable will store and what will be the (range)size of the values. Commonly used data types in C++ are below:
  1. Character
  2. Integer
  3. Floating Point
  4. Boolean
  5. Unsigned

A.  Character data type:

The ‘char’ keyword represents the character data type in the program. Every character belonging to the ASCII character set is called a character data type in C++. The maxi size of char data type is 1 byte (8 bits). Signed char and unsigned char are its two types. They occupy the same amount of memory space. Consider the following line of code:

Char x;
Here, x is a character type variable that occupies 1 byte of memory. Variable declared as char data type are used to store character constant. Character constants are always represented with single quotes. For example:

char Waleed2khan;
Waleed2khan= ‘K’
Here, Waleed is a character type variable that need 1 byte of memory to store character constant, K, which stands for Khan.

B.  Integer data type:

The data types which store only integer numbers such as 100, -200 etc. are called integer data types. Its sub types are:
  1. Integer
  2. Short Integer
  3. Long Integer
Int data types: The keyword int stands for the integer data type in C++ and normally has two bytes of memory (16 bits). A 16-bit integer may fall in the range of -215 to 215-1, which means that it can store values in the range of -32768 to 32767.
Short int data types: short int is used to declare the short integer data type in C++. The max size of the short int is 2 bytes (16 bits). It may fall in the range -215 to 215-1, which means that can store the values from -32768 to 32767.
Long int data types: Long int stands for long integer data types and is used in C++ t store larger integer values. Its size is 4 bytes it means that it can store values in the range of -2147483648 to 2147483647.

Fundamental data types in C++

C.  Floating point data type:

Integers are only used for storing whole numbers, but sometimes we need to store very large numbers, or numbers with a decimal point. Variables of floating point types hold real numbers, such as 4.0, 2.5, 3.33, or 0.1226. Three types of floating data are below:

  1. Float
  2. Double
  3. Long double
Float: In C++, the float data types is used to declare floating point type of variables to store numbers with decimal point. Its size is 4 bytes (32 bits).
Double: Double is a keyword to represent double precision floating point numbers in C++. Double data type needs 8 bytes (64 bits) of memory to store the value. The size of double data type is a rational number in the same range as long float and is stored in the form of floating point representation with binary mantissa and exponent.
Long double: In C++, the long double data types is used to declare long double type of variables to represent long double precision floating point numbers in C++. It needs 10 bytes (80 bits) of RAM.


D.  Boolean data type:

Bool is the keyword used to represent Boolean data types. It is able of holding any one of the two values: true (1) or false (0). Bool flag;



E.  Unsigned data type:

The data types discussed so far are signed data types it means that one bit is reserved for the value (i.e. +/-). The unsigned numbers are whole numbers and always hold positive values starting from 0 sill its maximum size. Here, the sign bit also used for the value which means no bit is reserved for holding a sign (+/-). The unsigned numbers are of four types:
  1. Unsigned Integer
  2. Unsigned Short integer
  3. Unsigned Char
  4. Unsigned Boolean
A summary of the basic fundamental data types in C++, as well as the range of values that can be represented with each one is given in Table below:


Fundamental data types in C++






Previous
Next Post »