我试图用指针理解一些东西,所以我写了这段代码:
#include <stdio.h>
int main(void)
{
char s[] = "asd";
char **p = &s;
printf("The value of s is: %p\n", s);
printf("The direction of s is: %p\n", &s);
printf("The value of p is: %p\n", p);
printf("The direction of p is: %p\n", &p);
printf("The direction of s[0] is: %p\n", &s[0]);
printf("The direction of s[1] is: %p\n", &s[1]);
printf("The direction of s[2] is: %p\n", &s[2]);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
用gcc编译时我得到以下警告:
$ gcc main.c -o main-bin -ansi -pedantic -Wall -lm
main.c: In function ‘main’: …Run Code Online (Sandbox Code Playgroud)