Variable size: int, short, long, char, float and double : Variable size « Language Basics « C++ Tutorial






#include <iostream>
 
 int main()
 {
     std::cout << "The size of an int is:\t\t";
     std::cout << sizeof(int) << " bytes.\n";
     std::cout << "The size of a short int is:\t"; 
     std::cout << sizeof(short) << " bytes.\n";
     std::cout << "The size of a long int is:\t";
     std::cout << sizeof(long) << " bytes.\n";
     std::cout << "The size of a char is:\t\t";
     std::cout << sizeof(char) << " bytes.\n";
     std::cout << "The size of a float is:\t\t";
     std::cout << sizeof(float) << " bytes.\n";
     std::cout << "The size of a double is:\t";
     std::cout << sizeof(double) << " bytes.\n";
 
     return 0;
 }
The size of an int is:          4 bytes.
The size of a short int is:     2 bytes.
The size of a long int is:      4 bytes.
The size of a char is:          1 bytes.
The size of a float is:         4 bytes.
The size of a double is:        8 bytes.








1.4.Variable size
1.4.1.Variable size: int, short, long, char, float and double