[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.