Đang chuẩn bị liên kết để tải về tài liệu:
Programming in Objective-C 2.0 edition phần 6
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
C nhân vật biến được định nghĩa và khởi tạo nhân vật 'Q'. Trong dòng tiếp theo của chương trình, charPtr biến được định nghĩa là loại "con trỏ đến char" có nghĩa rằng bất cứ điều gì giá trị được lưu trữ bên trong biến này phải được coi là một tham chiếu gián tiếp (con trỏ) cho một nhân vật. | 286 Chapter 13 Underlying C Language Features The character variable c is defined and initialized to the character q . In the next line of the program the variable charPtr is defined to be of type pointer to char meaning that whatever value is stored inside this variable should be treated as an indirect reference pointer to a character. Notice that you can assign an initial value to this variable in the normal fashion.The value you assign to charPtr in the program is a pointer to the variable c which is obtained by applying the address operator to the variable c. Note that this initialization would have generated a compiler error had c been defined after this statement because a variable must always be declared before its value can be referenced in an expression. The declaration of the variable charPtr and the assignment of its initial value could have been equivalently expressed in two separate statements as follows char charPtr charPtr c and not by the statements char charPtr charPtr c as might be implied from the single line declaration . Remember that the value of a pointer in Objective-C is meaningless until it is set to point to something. The first NSLog call simply displays the contents of the variable c and the contents of the variable referenced by charPtr. Because you set charPtr to point to the variable c the value displayed is the contents of c as verified by the first line of the program s output. In the next line of the program the character is assigned to the character variable c. Because charPtr still points to the variable c displaying the value of charPtr in the subsequent NSLog call correctly displays this new value of c at the terminal.This is an important concept. Unless the value of charPtr changes the expression charPtr always accesses the value of c.Thus as the value of c changes so does the value of charPtr. The previous discussion can help you understand how the program statement that appears next in the program works.We mentioned that .