C语言的二级指针简述

用C语言指针作为函数返回值:
C语言允许函数的返回值是一个指针(地址),我们将这样的函数称为指针函数
函数运行结束后会销毁在它内部定义的所有局部数据

#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;
}

C语言二级指针(指向指针的指针):
指针可以指向一份普通类型的数据,例如 int、double、char 等,也可以指向一份指针类型的数据,例如 int *、double *、char * 等。
如果一个指针指向的是另外一个指针,我们就称它为二级指针,或者指向指针的指针

#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

e的地址是0xbfe7c530  , b是指针地址是0xbfe7c530 ,正好b指向e

b指针变量本身的地址是0xbfe7c534 , c是指针地址是0xbfe7c534 ,整好c指向b

猜你喜欢

转载自www.linuxidc.com/Linux/2017-11/148876.htm