Second-level pointers

Source: Internet
Author: User

The second level of the pointer, has been their own relatively vague existence, until one day dreaming and then woke up to understand the quack

I'm not saying anything, directly on the code.

//define DBLog#defineDBLog (FMT, ...) NSLog (@ "\nfunction:%s \nline:%d" FMT), __pretty_function__,__line__, # #__VA_ARGS__);#defineDLog (FMT, ...) NSLog (@ "%s [line%d]" FMT), __pretty_function__, __line__, # #__VA_ARGS__);#import "ViewController.h"@interfaceViewcontroller ()@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; //general usage of level two pointers    /** * @author Liu June, 15-08-18 * * The pass of a first-hand pointer is simply the pass of the value, although the Singlepointarr is initialized in the method (but in the function is a local variable) * * For a first-level pointer , the understanding of level two pointers, mainly: first-level pointers are the transfer of their own values, level two pointers are the delivery of their own addresses, * in the first case, Singlpointarr is an uninitialized array, that is, the array points to a nil, In the Initsinglearray actually wore a nil in, and then it can be understood that in the function is actually the initialization of arr array, and arr is a local variable, out of the scope of the function disappears, so the first outside there is no value to print out * The second case, Although it is still a first-level pointer, but because it has been initialized, it points to an array that has already opened up memory space, so the input function is to point to the address of this space, and in the function to modify ARR is equivalent to directly manipulate the original array, so when printed outside, the array is changed * The third case is that the array is not comfortable, although the point is a nil, but the transfer into the function is its own address, in the function of the direct operation of its own address, the equivalent of holding itself in the initialization, so the function is printed outside the initialized value//So for must pass the two level pointer, The variables outside must be nil.*/Nsarray*singlepointarr =Nil;    [Self Initsinglearray:singlepointarr]; DBLog (@"\n1. Singlepointarr =%@\n point:%p\n\n", Singlepointarr,singlepointarr); //DLog (@ "\n1. Singlepointarr =%@\n point:%p", Singlepointarr,singlepointarr);Nsmutablearray*SINGLEPOINTARR1 = @[@"1",@"2",@"3",@"4",@"5"].mutablecopy;    [Self changesinglearray:singlepointarr1]; DBLog (@"\n2.changesingle:%@ \ point:%p \ n", SINGLEPOINTARR1,SINGLEPOINTARR1); Nsarray*doublepointarr =Nil; [Self Initdoublearray:&Doublepointarr]; DBLog (@"\n2.doublepointarr =%@\n point:%p \ n", Doublepointarr,doublepointarr); }//Pass A level pointer- (void) Initsinglearray: (Nsarray *) arr {DBLog (@"\n1.%@\n\n", arr); Arr= @[@" One",@" Both"]; DBLog (@"\n1. arr =%@\n%p\n\n", Arr,arr);}- (void) Changesinglearray: (Nsmutablearray *arr {[arr removelastobject]; }//Pass Level two pointer- (void) Initdoublearray: (Nsarray * *) Arr {*arr = @[@"1",@"2"]; DBLog (@"\n2. arr =%@ \ n point:%p\n\n", *arr,*arr);}@end

Second-level pointers

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.