Cpp Type Size Test

Info of Test System

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
       _,met$$$$$gg.          mason@LinuxVM
    ,g$$$$$$$$$$$$$$$P.       -------------
  ,g$$P"     """Y$$.".        OS: Debian GNU/Linux 12 (bookworm) x86_64
 ,$$P'              `$$$.     Host: VMware Virtual Platform None
',$$P       ,ggs.     `$$b:   Kernel: 6.1.0-26-amd64
`d$$'     ,$P"'   .    $$$    Uptime: 5 hours, 31 mins
 $$P      d$'     ,    $$P    Packages: 557 (dpkg)
 $$:      $$.   -    ,d$$'    Shell: bash 5.2.15
 $$;      Y$b._   _,d$P'      Resolution: 1280x800
 Y$$.    `.`"Y$$$$P"'         Terminal: /dev/pts/0
 `$$b      "-.__              CPU: 12th Gen Intel i3-12100 (2) @ 3.302GHz
  `Y$$                        GPU: 00:0f.0 VMware SVGA II Adapter
   `Y$$.                      Memory: 696MiB / 1932MiB
     `$$b.
       `Y$$b.
          `"Y$b._
              `"""

Size of C++ Types

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
sizeof(bool) = 1
sizeof(char) = 1
sizeof(short int) = 2
sizeof(int) = 4
sizeof(unsigned int) = 4
sizeof(unsigned long) = 8
sizeof(long) = 8
sizeof(long long) = 8
sizeof(float) = 4
sizeof(double) = 8
sizeof(long double) = 16

Source Code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#include <iostream>

int main(int argc, char* argv[]){
    std::cout << "sizeof(bool) = " << sizeof(bool) << std::endl
              << "sizeof(char) = " << sizeof(char) << std::endl
              << "sizeof(short int) = " << sizeof(short int) << std::endl
              << "sizeof(int) = " << sizeof(int) << std::endl
              << "sizeof(unsigned int) = " << sizeof(unsigned int) << std::endl
              << "sizeof(unsigned long) = " << sizeof(unsigned long) << std::endl
              << "sizeof(long) = " << sizeof(long) << std::endl
              << "sizeof(long long) = " << sizeof(long long) << std::endl
              << "sizeof(float) = " << sizeof(float) << std::endl
              << "sizeof(double) = " << sizeof(double) << std::endl
              << "sizeof(long double) = " << sizeof(long double) << std::endl;
    return 0;
}
Licensed under CC BY-NC-SA 4.0
Built with Hugo
Theme Stack designed by Jimmy