Today, we will mainly explain how to use the data types and expressions of Object-C, four basic data types of Object-C: int, float, double, char
1.int type
There are two special formats in object-C:
1. if the first integer is 0, the integer is expressed in octal notation. For example, 050 indicates 40 in decimal format (0*64 + 5*8 + 0*1 = 40 ), output in nslog () is as follows: (% I is output in decimal format, % O is output in octal format but leading 0 is not output, % # O is output in octal format including leading 0)
# Import <Foundation/Foundation. h> int main (INT argc, const char * argv []) {@ autoreleasepool {int A = 050; nslog (@ "% I", ); nslog (@ "% O", a); nslog (@ "% # O", a);} return 0;} output result: 01:27:37. 752 demo2 [685: 29598] 402014-10-30 01:27:37. 753 demo2 [685: 29598] 502014-10-30 01:27:37. 753 demo2 [685: 29598] 050 program ended with exit code: 0
2. if the integer is 0 or X (both uppercase and lowercase), the integer is expressed in hexadecimal notation (note: the hexadecimal number consists of 0-9 numbers and letters between A and F (or a to F), where the A-F represents the number 10-15), such as 0xffef0d output is as follows:
# Import <Foundation/Foundation. h> int main (INT argc, const char * argv []) {@ autoreleasepool {int B = 0xffef0d; nslog (@ "% I", B ); nslog (@ "% x", B); nslog (@ "% # X", B);} return 0;} output result: 01:37:35. 516 demo2 [702: 32548] 167728772014-10-30 01:37:35. 516 demo2 [702: 32548] ffef0d2014-10-30 01:37:35. 516 demo2 [702: 32548] 0xffef0d
Learning Object-C from scratch --- day 4