Size of common data types in C Language

Source: Internet
Author: User

In C, the size of common data types varies with operating systems, compilers, and other factors.

 1 # Include <stdio. h>
2 # Include < Float . H>
3
4 # Define Pr (x) printf ("% 11 S: % 2lu bytes \ n", # X, (unsigned long) sizeof (x ))
5
6 Int Main ( Void )
7 {
8 Pr (size_t );
9 Pr ( Void *);
10 Pr ( Char );
11 Pr ( Short );
12 Pr ( Int );
13 Pr ( Long );
14 Pr ( Long Long );
15 Pr ( Float );
16 Pr ( Double );
17 Pr ( Long Double );
18 Printf ( " \ N ---- dig ------- Epsilon ----------- min ----------- MAX \ n " );
19 Printf ( " Flt % 3d %-14E %-14E %-14E \ n " , Flt_dig, flt_epsilon, flt_min, flt_max );
20 Printf ( " DBL % 3d %-14E %-14E %-14E \ n " , Dbl_dig, dbl_epsilon, dbl_min, dbl_max );
21 Printf ( " Ldbl % 3d %-14le %-14le %-14le \ n " , Ldbl_dig, ldbl_epsilon, ldbl_min, ldbl_max );
22 Printf ( " ---- --- -------------- \ N " );
23 Return 0 ;
24 }

ThisProgramRunning results in ideone.com are as follows (http://ideone.com/jH1dT ):

Size_t: 4 bytes void *: 4 bytes CHAR: 1 bytes short: 2 bytes INT: 4 bytes long: 4 bytes long: 8 bytes float: 4 bytes double: 8 byteslong double: 12 bytes ---- dig ------- Epsilon --------- min ----------- Max FLT 6 1.192093e-07 1.175494e-38 3.402823e + 38 DBL 15 minutes-16 minutes-308 bytes + 308 ldbl 18 minutes-19 minutes-4932 1.189731e + 4932 -------------------------------------------------

In fact, this is a 32-bit Linux operating system, and the compiler is GCC 4.3.4.

The running result of this program in opensuse 12.1 64-bit operating system is as follows (the compiler is GCC 4.6.2 ):

Size_t: 8 bytes void *: 8 bytes CHAR: 1 bytes short: 2 bytes INT: 4 bytes long: 8 bytes long: 8 bytes float: 4 bytes double: 8 byteslong double: 16 bytes ---- dig ------- Epsilon --------- min ----------- Max FLT 6 1.192093e-07 1.175494e-38 3.402823e + 38 DBL 15 minutes-16 minutes-308 bytes + 308 ldbl 18 minutes-19 minutes-4932 1.189731e + 4932 -------------------------------------------------

In the above results, long double is 16 bytes, but in fact its range and precision are the same as those of 12 bytes, it may be because of the consideration of alignment of the byte boundary in the 64-bit operating system.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.