Programming in Objective-C 2.0 edition phần 6

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 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 is an important concept. Unless the value of charPtr changes the expression charPtr always accesses the value of 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 mentioned that .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.