Object-C pointer to pointer

Source: Internet
Author: User

It is required to define a function from the outside and change the value of C in the main function.

Steps:

1. Call a function. If you want to modify the value of the variable in the main function externally, you need to pass the address of this value to the function. & C

2. In an external function, the pointer is used to modify the value pointing to C.

1 void changec (char * P) {2 3 // pass the pointer. modify the value of C 4 5 * P = 9; 6 7} 8 9 int main (INT argc, const char * argv []) {10 11 @ autoreleasepool {12 13 // define a char type variable C14 15 char c = 10; 16 17 // call the changec function. pass the c Address to the function, 18 19 changec (& C); 20 21 nslog (@ "% I", c); 22 23} 24 25 return 0; 26 27}

Relationship in memory

Send the STR address (the pointer is the address) to the function. You can modify the value of the bucket pointed to by STR through str1.

# Import <Foundation/Foundation. h> void changestr (nsstring ** str1) {* str1 = @ "hi";} int main (INT argc, const char * argv []) {@ autoreleasepool {// defines a pointer pointing to the address with the content @ "hello". Str itself is a pointer nsstring * STR = @ "hello"; // when calling a function, modify the STR content changestr (& Str); nslog (@ "% @", STR);} return 0 ;}

 

Object-C pointer to pointer

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.