Basic data type length for C language

Source: Internet
Author: User

PS: The following is a test result in the 64-bit environment of Xcode's editor, online search for the differences between the 64-bit and 32-bit data types.

Main.m

1 #import<Foundation/Foundation.h>2 voidBasicdatatypeinc () {3Nsmutablestring *mstrinfo =[[Nsmutablestring alloc] init];4     //(Numeric Type-"integer") integer type 2147483648 to 21474836475     intIntegerval =888;6     //(Numeric Type-"integer") short integer type7      Short intShortintegerval =888;8     //(Numeric Type-"integer") long integer type9     Long intLongintegerval =888;Ten      One     //(numeric Type-"float type") single-precision type, where there is a loss of precision (as follows: Because of the single-precision type, the number of significant digits is 6-7 bits.) And the integer is 3 bits, so the decimal 3 or 4 digits are not valid numbers) A     floatFloatval =888.8888888888; -     //(numeric Type-"floating point") double type (as follows: Because it is a double type, the number of significant digits is 15-16 bits.) VC6.0, however, retains a maximum of 6 digits after the decimal, rounding out the remainder) -     DoubleDoubleval =888.8888888888; the      -      -     //Character Type -     CharCharval ='a'; +     CharCharVal2 = the; -     //the type of the string, essentially using the pointer type +     Char*charval3 ="I am a string."; A      at     //Boolean, not 0 and false, which means 1 is true -     BOOLBoolval =true; -     BOOLBoolVal2 =-1; -     BOOLBoolVal3 =1; -     BOOLBoolVal4 =2; -[Mstrinfo AppendFormat:@"\nintegerval=%i\n", Integerval];//integerval=888 in[Mstrinfo AppendFormat:@"shortintegerval=%hi\n", Shortintegerval];//shortintegerval=888 -[Mstrinfo AppendFormat:@"longintegerval=%li\n", Longintegerval];//longintegerval=888 to[Mstrinfo AppendFormat:@"floatval=%f\n", Floatval];//floatval=888.888916 +[Mstrinfo AppendFormat:@"doubleval=%f\n", Doubleval];//doubleval=888.888889 -[Mstrinfo AppendFormat:@"charval=%c\n", Charval];//Charval=a the[Mstrinfo AppendFormat:@"charval2=%c\n", CharVal2];//Charval2=a *[Mstrinfo AppendFormat:@"charval3=%s\n", CharVal3];//charval3=i am a string. $[Mstrinfo AppendFormat:@"boolval=%i\n", Boolval];//boolval=1Panax Notoginseng[Mstrinfo AppendFormat:@"boolval2=%i\n", BoolVal2];//boolval2=1 -[Mstrinfo AppendFormat:@"boolval3=%i\n", BoolVal3];//boolval3=1 the[Mstrinfo AppendFormat:@"boolval4=%i\n\n\n", BoolVal4];//boolval4=1 +      A      the[Mstrinfo AppendFormat:@"sizeof (int) is%lu bytes \ n",sizeof(int)];//sizeof (int) is 4 bytes +[Mstrinfo AppendFormat:@"sizeof (short int) is%lu bytes \ n",sizeof( Short int)];//sizeof (short int) is 2 bytes -[Mstrinfo AppendFormat:@"sizeof (long int) is%lu bytes \ n",sizeof(Long int)];//sizeof (long int) is 8 bytes $[Mstrinfo AppendFormat:@"sizeof (float) is%lu bytes \ n",sizeof(float)];//sizeof (float) is 4 bytes $[Mstrinfo AppendFormat:@"sizeof (double) is%lu bytes \ n",sizeof(Double)];//sizeof (double) is 8 bytes -[Mstrinfo AppendFormat:@"sizeof (char) is%lu bytes \ n",sizeof(Char)];//sizeof (char) is 1 bytes -[Mstrinfo AppendFormat:@"sizeof (BOOL) is a%lu byte",sizeof(BOOL)];//sizeof (bool) is 1 bytes theNSLog (@"%@", mstrinfo); - }Wuyi intMainintargcConst Char*argv[]) { the @autoreleasepool { -NSLog (@"basic data type length for C language"); Wu basicdatatypeinc (); -     } About     return 0; $}

Results:

1  -- to- the  at: on:06.687cbasicdatatype[917:36520] The basic data type length of the C language2  -- to- the  at: on:06.688cbasicdatatype[917:36520] 3Integerval=8884Shortintegerval=8885Longintegerval=8886Floatval=888.8889167Doubleval=888.8888898Charval=a9Charval2=aTenCharval3=i am Astring. OneBoolval=1 ABoolval2=1 -boolval3=1 -boolval4=1 the sizeof(int) is 4 bytes - sizeof( Short int) is 2 bytes - sizeof(Long int) is 8 bytes - sizeof(float) is 4 bytes + sizeof(Double) is 8 bytes - sizeof(Char) is 1 bytes + sizeof(BOOL) is 1 bytes

Basic data type length for C language

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.