What does the C++ standard state the size of int, long type to be?

前端 未结 24 2948
无人及你
无人及你 2020-11-21 04:42

I\'m looking for detailed information regarding the size of basic C++ types. I know that it depends on the architecture (16 bits, 32 bits, 64 bits) and the compiler.

24条回答
  •  轮回少年
    2020-11-21 04:47

    When it comes to built in types for different architectures and different compilers just run the following code on your architecture with your compiler to see what it outputs. Below shows my Ubuntu 13.04 (Raring Ringtail) 64 bit g++4.7.3 output. Also please note what was answered below which is why the output is ordered as such:

    "There are five standard signed integer types: signed char, short int, int, long int, and long long int. In this list, each type provides at least as much storage as those preceding it in the list."

    #include 
    
    int main ( int argc, char * argv[] )
    {
      std::cout<< "size of char: " << sizeof (char) << std::endl;
      std::cout<< "size of short: " << sizeof (short) << std::endl;
      std::cout<< "size of int: " << sizeof (int) << std::endl;
      std::cout<< "size of long: " << sizeof (long) << std::endl;
      std::cout<< "size of long long: " << sizeof (long long) << std::endl;
    
      std::cout<< "size of float: " << sizeof (float) << std::endl;
      std::cout<< "size of double: " << sizeof (double) << std::endl;
    
      std::cout<< "size of pointer: " << sizeof (int *) << std::endl;
    }
    
    
    size of char: 1
    size of short: 2
    size of int: 4
    size of long: 8
    size of long long: 8
    size of float: 4
    size of double: 8
    size of pointer: 8
    

提交回复
热议问题