Fundamental data types in C Programming Language

Fundamental data types in C Programming Language

In this article,  we are going to talk Fundamental data types in C Programming Language.

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 type tells the compiler that what types of data, means integer, character or floating point etc. the variable will store and what will be the range of the values.

The most commonly used data types in C++ are:

  • Character
  • Integer
  • Floating point
  • Boolean
  • Unsigned

Character data type

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

char x;

Here, x is a character type variables that occupies 1 byte of memory. Variables declared as char data type are used to store character constants. Character constants are always represented by single quotes. For example:

char gender;

gender = ‘M’;

Here, gender is a character type variable that occupies 1 byte of memory and store character constant, M, which stands for Male.

Integer data types

The data types which store only integer numbers such as 100, -200 etc. are called integer data types. Its subtypes are:

  • int
  • short int
  • long

int data type

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 type

short int is used to declare the short integer data type in C++. The maximum size of the short int data type is 2 bytes (16 bits). It may fall in the range -215 to 215-1, which means that it can store the values from -32768 to 32767.

long int data type

long int stands for long integer data type and is used in C++ to store larger integer values. Its size is 4 bytes (32 bits) which means that it can stores values in the range of -2147483648 to 2147483647.

Also Read  Basic Structure of a C program for Beginner

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. The data types which are used to store such type of data are called floating point data types. Variables of floating point types hold real numbers, such as 4.0, 2.5, 3.33, or 0.1226. there are three different types of floating point data types:

  • float
  • double
  • long double

float data type

In C++, the float data type is used to declare floating point type of variables to store numbers with decimal point. It needs 4 bytes (32 bits) of memory to store values.

double data type

double is a keyword to represent double precision floating point numbers in C++. double data type occupies 8 bytes (64 bits) of memory. 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 data type

In C++, the long double data type is used to declare  long double type of variables to represent  long double precision point numbers in C++. It needs 10 bytes (80 bits) of memory space in the RAM.

Boolean data type

bool is the keyword used to represent Boolean data type. It is capable of holding one of the two values: true (1) or false (0). It occupies 1 byte of memory.

Unsigned data type

The data types discussed so far are signed data types which means that one bit is reserved for the sign of the value (i.e. +/-). The unsigned numbers are whole numbers and always hold positive values starting from 0 till 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 may be classified into four types:

  • unsigned char
  • unsigned integer
  • unsigned short integer
  • unsigned long integer

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 below in the table.

S. No Type Typical Bit Width Typical Range
1 char 1byte -127 to 127 or 0 to 255
2 unsigned char 1byte 0 to 255
3 signed char 1byte -127 to 127
4 int 4bytes -2147483648 to 2147483647
5 unsigned int 4bytes 0 to 4294967295
6 signed int 4bytes -2147483648 to 2147483647
7 short int 2bytes -32768 to 32767
8 unsigned short int Range 0 to 65,535
9 signed short int Range -32768 to 32767
10 long int 4bytes -2,147,483,648 to 2,147,483,647
11 signed long int 4bytes same as long int
12 unsigned long int 4bytes 0 to 4,294,967,295
13 float 4bytes +/- 3.4e +/- 38 (~7 digits)
14 double 8bytes +/- 1.7e +/- 308 (~15 digits)
15 long double 8bytes +/- 1.7e +/- 308 (~15 digits)
Also Read  post a comment in c programming language and statement terminator

Have any Question or Comment?

One comment on “Fundamental data types in C Programming Language


Really appriciated your article. thank you for it.


Leave a Reply

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