1. Variable addresses can be obtained through & variables:
#include <stdio.h>
int main(void)
{
int num = 10;
printf("变量值: %d\n",num);
printf("变量址: %d\n",&num);
getchar();
return 0;
}
2. A variable that represents a variable address is a pointer:
#include <stdio.h>
int main(void)
{
int num = 10;
int *p = #
printf("%d,%p\n",num,p);
getchar();
return 0;
}
3. * The pointer is the same as the variable itself:
#include <stdio.h>
int main(void)
{
int num = 10;
int *p = #
printf("%d,%p,%d\n",num,p,*p);
*p = 11;
printf("%d,%p,%d\n",num,p,*p);
(*p)++;
printf("%d,%p,%d\n",num,p,*p);
num = 99;
printf("%d,%p,%d\n",num,p,*p);
getchar();
return 0;
}
4. Be aware of initialization when declaring pointers, and no pointers to initialize are dangerous:
#include <stdio.h>
int main(void)
{
int n1 = 11;
int n2 = 22;
int *p = NULL; /* 初始化为空 */
p = &n1;
printf("%d,%p,%d\n",n1,p,*p);
p = &n2;
printf("%d,%p,%d\n",n2,p,*p);
getchar();
return 0;
}