指针的操作
1 #include <stdio.h> 2 int main() 3 { 4 int num1 = 1024; 5 int num2 = 2048; 6 int *ptr1; 7 int *ptr2; 8 9 ptr1 = &num1; 10 ptr2 = &num2; 11 printf("num1的值是%d\tnum1的地址是:%p\n",num1,ptr1); 12 printf("num2的值是%d\tnum2的地址是: %p\n",num2,ptr2); 13 14 //变量1的值,赋给变量2 15 16 //num2 = num1; = *ptr2 = *ptr1; 17 18 // *ptr2 = *ptr1; 19 // printf("重新变量赋值:\n"); 20 // printf("num1的值是%d\tnum1的地址是:%p\n",num1,ptr1); 21 // printf("num2的值是%d\tnum2的地址是: %p\n",num2,ptr2); 22 23 ptr2 = ptr1; //指针的操作 24 printf("重新地址赋值:\n"); 25 printf("num1的值是%d\tnum1的地址是:%p\n",num1,ptr1); 26 printf("num2的值是%d\tnum2的地址是: %p\n",num2,ptr2); 27 28 *ptr2 = 11111111; 29 printf("重新赋值:\n"); 30 printf("num1的值是%d\tnum1的地址是:%p\n",num1,ptr1); 31 printf("num2的值是%d\tnum2的地址是: %p\n",num2,ptr2); 32 }
本文来自博客园,作者:Bytezero!,转载请注明原文链接:https://www.cnblogs.com/Bytezero/p/15071980.html