Type of bool in Object-c

Source: Internet
Author: User

The Boolean type in Object-c is 10 years older than the bool type in C, and has a yes and no two values. The Boolean type bool in Object-c is actually a signed character type (signed char), which uses a space of 1byte, or 8bit, where Yes is defined as 1,no defined as 0. Assigning an integer greater than 1 bytes (such as short or int) to a bool variable is truncated and retains only the 8 bits at the end.

The following are examples of the types of bool used in OBJECT-C:

#import<Foundation/Foundation.h>//compare whether two int numbers are the sameBOOL Areintsdifferent (intThing1,intthing2) {    if(thing1==thing2)returnNO; Else        returnYES;}//returns the NSString string corresponding to the number of type boolNSString *boolstring (BOOL yesNo) {if(yesno==YES)return @"YES"; Else        return @"NO"; }intMainintargcConst Char*argv[])    {BOOL aretheydifferent; Aretheydifferent= Areintsdifferent (6,6); //The following%@ represents the NSString placeholderNSLog (@"is %d and%d different?%@",6,6, Boolstring (aretheydifferent)); Aretheydifferent= Areintsdifferent ( at, the); NSLog (@"is %d and%d different?%@", at, the, Boolstring (aretheydifferent)); return 0;}

Results of the output:

2016-04-04 23:18:48.964 hello-obj[1267:84194] is 6 and 6 different? no2016-04-04 23:18:48.965 hello-obj[1267:84194] is and different? YES

Type of bool in Object-c

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.