Differences between BOOL and bool in OC language: ocbool

Source: Internet
Author: User

Differences between BOOL and bool in OC language: ocbool

1. Different Types

BOOL is int type;

Bool is boolean;

 

2. Different Lengths

Bool has only one byte;

The BOOL length depends on the actual environment. Generally, it can be regarded as 4 bytes;

3. Different values

Bool values: false and true, which are the difference between 0 and 1;

BOOL values: FALSE and TRUE, which are the difference between 0 and non-0;

The following is an example.

# Import <Foundation/Foundation. h>

 

Int main (int argc, const char * argv []) {

@ Autoreleasepool {

BOOL b1 = 3;

Bool b2 = 3;

BOOL b3= 256;

Bool b4 = 256;

NSLog (@ "b1 = % d", b1 );

NSLog (@ "b2 = % d", b2 );

NSLog (@ "b3 = % d", b3 );

NSLog (@ "b4 = % d", b4 );

}

Return 0;

}

The output is as follows:

Because b2 is of the bool type, b2 can only be 1 or 0; that is, b2 = b4 = 1.

Because b3 is of the BOOL type and has 8-bit storage space, the value range of b3 is-256 ~ 255.

Because 256 is converted to hexadecimal = 0X100, b3 = 0; b1 = 3.

Finally, we can conclude that if the variable is of the BOOL type, as long as the value is greater than 255, the result can only be a low 8-bit value;

If b3 = 272, the print result is b3 = 16.

Related Article

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.