指针
``#include <stdio.h>
int main() {
int num1 = 100;
int num2 = 200;
int num3 = 300;
int *p_num1 = &num1;
int *p_num11;
int *p_num11;
int *p_num2 = &num2;
printf(“the num1 is %d\n”,num1);
printf(“the pointer of num1 is %p\n”,&num1);
printf(“the pointer of num1 is %p\n”,&num2);
printf(“the pointer of num1 is %p\n”,&num3);
printf(“the type of int size is %ld\n”, sizeof(int));
printf("------------------------------------------\n");
printf(“the num1 is %d by p_num1\n”, *p_num1);
printf(“the pointer is %p\n”, p_num1);
printf(“the pointer of p_num1 is %p\n”, &p_num1);
p_num11 = p_num1;
printf(“the num1 is %d by p_num11\n”, *p_num11);
*p_num1 = 1000;
printf(“the num1 is %d\n”, num1);
printf(“the num1 is %d by p_num1\n”, *p_num1);
printf(“the num1 is %d by p_num11\n”, *p_num11);
*p_num2 = 2000;
printf(“the num1 is %d by p_num2\n”, *p_num2);
p_num2 = p_num11;
printf(“the num1 is %d by p_num1\n”, *p_num2);
printf("------------------------------------\n");
num1 = *p_num1 + 1;
*p_num1 = *p_num1 + 1;
num1++;
*p_num1 = *p_num1 + 1;
printf("the num1 is %d\n", num1);
printf("the num1 is %d by p_num1\n", *p_num1);
printf("------------------------------------\n");
printf("the num is %d by p_num1 + 2 \n",*(p_num1 + 2));
printf("the value (p_num[2]) is %d\n", p_num1[2]);
p_num1 = &num1;
p_num2 = &num2;
printf ("the dist of p_num1 and p_num2 is %ld\n",p_num2 - p_num1);
printf ("the dist of p_num1 and p_num2 is %ld\n",(long)p_num2 - (long)p_num1);
printf ("------------------------------------------------------\n");
p_num2++;
printf ("the p_num2 is %p\n", p_num2);
printf ("the value of *p_num2 is %d\n", *p_num2);
}
字符串
```c
#include <stdio.h>
#include <string.h>
int main() {
char str[] = "hello world";
printf("the str = %s\n",str);
printf("the pointer is %p\n",str);
str[0] = 'H';
str[6] = 'W';
printf("the changde str = %s\n",str);
printf("the length of str is %d\n",strlen(str));
char str2[] = "hello\0 world";
printf("the str2 = %s\n",str2);
printf("the pointer is %p\n",str2);
printf("the world of str2 = %s\n",&str2[0]);
printf("the world of str2 = world by %s\n",(str2+6));
char str3[] = {'h','e','l','l','o','\0'};
printf("the str3 = %s\n",str3);
printf("the pointer of str3 is %p\n",str3);
char *p_str = str;
printf("the str =%s\n by p_str\n",p_str);
}
~