C++ Program to find size of int, float, double and char in Your System

In this basic C++ program, we will have a look at how to find the size of int, float, double and char in your system.

sizeof the operator is used to find the size of the variable.

sizeof(dataType);

C++ Program to find the size of int, float, double and char in Your System

This program declares 4 variables of type int, float, double and char. Then, the size of each variable is evaluated using sizeof operator.

#include <iostream>
using namespace std;
int main() {    
   cout<<"Size of int is "<<sizeof(int)<<" bytes"<<endl;
   cout<<"Size of float is "<<sizeof(float)<<" bytes"<<endl;
   cout<<"Size of double is "<<sizeof(double)<<" bytes"<<endl;
   cout<<"Size of char is "<<sizeof(char)<<" byte"<<endl;
   return 0;
}

Output

Size of char: 1 byte
Size of int: 4 bytes
Size of float: 4 bytes
Size of double: 8 bytes

Leave a Comment

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