[Programming] The second-level pointer of C language, programming the C language pointer

Source: Internet
Author: User

[Programming] The second-level pointer of C language, programming the C language pointer

Use C language pointer as function return value:
The C language allows the function to return a pointer (Address). We call such a function a pointer function.
After the function is executed, all local data defined in the function is destroyed.

#include<stdio.h>
#include<string.h>
char * strlong(char *d,char *e){
        if(strlen(d) > strlen(e)){
                return d;
        }else{
                return e;
        }   
}
int main(){
        char *a="taoshihan";
        char *b="taoaaaaaaa";
        char *c; 
        c=strlong(a,b);
        printf("c=%s",c);
        return 0;
}

 

Level 2 pointer of C language (pointer to pointer):
A pointer can point to a common type of data, such as int, double, and char. It can also point to a pointer type of data, such as int *, double *, and char.
If a pointer points to another pointer, we call it a second-level pointer or a pointer to the pointer.

#include<stdio.h>
int main(){

        int e=100;
        int *b=&e;
        int **c=&b;
        printf("%d , %d , %d \n",e,*b,**c);
        printf("&e=%#x , b=%#x , &b=%#x , c=%#x \n",&e,b,&b,c);

        return 0;
}

& E = 0xbfe7c530, B = 0xbfe7c530, & B = 0xbfe7c534, c = 0xbfe7c534

The address of e is 0xbfe7c530, B is the pointer address is 0xbfe7c530, and B points to e.

The address of the B pointer variable itself is 0xbfe7c534, and the address of the c pointer is 0xbfe7c534.


Related Article

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.