Displays the number of bytes required to store an integer variable. - C++ Data Type

C++ examples for Data Type:Introduction

Introduction

Variable Types

Type Size Values
unsigned short 2 bytes 0 to 65,535
short 2 bytes -32,768 to 32,767
unsigned long 4 bytes 0 to 4,294,967,295
long 4 bytes -2,147,483,648 to 2,147,483,647
int4 bytes -2,147,483,648 to 2,147,483,647
unsigned int 4 bytes 0 to 4,294,967,295
long long int 8 bytes -9.2 quintillion to 9.2 quintillion
char 1 byte 256 character values
bool 1 byte true or false
float 4 bytes 1.2e-38 to 3.4e38
double 8 bytes 2.2e-308 to 1.8e308

Demo Code

#include <iostream> 
 
int main() /*w  w  w .j a  v  a 2  s . c om*/
{ 
    std::cout << "The size of an integer:\t\t"; 
    std::cout << sizeof(int) << " bytes\n"; 
    std::cout << "The size of a short integer:\t"; 
    std::cout << sizeof(short) << " bytes\n"; 
    std::cout << "The size of a long integer:\t"; 
    std::cout << sizeof(long) << " bytes\n"; 
    std::cout << "The size of a character:\t"; 
    std::cout << sizeof(char) << " bytes\n"; 
    std::cout << "The size of a boolean:\t\t"; 
    std::cout << sizeof(bool) << " bytes\n"; 
    std::cout << "The size of a float:\t\t"; 
    std::cout << sizeof(float) << " bytes\n"; 
    std::cout << "The size of a double float:\t"; 
    std::cout << sizeof(double) << " bytes\n"; 
    std::cout << "The size of a long long int:\t"; 
    std::cout << sizeof(long long int) << " bytes\n"; 

    return 0; 
}

Result


Related Tutorials