正在加载图片...
例8-1利用指针模拟寻找保险箱IfI know the name of the variable, I can get密码的过程it's value by name: 911IfIknowtheaddress of thevariable获取密码的两种方法is:12ff7c,thenIalso can get it'svalue byint main(void)address:911【intkey=911;/*变量key用于存放密码值911*/int*p_addr=NULL;/*变量p_addr是整型指针变量*/p_addr= &key;/*将key的地址赋给p_addr*/*通过变量key输出密码值*printf("The key is: %din", key);/*通过变量名key输出密码值*printf(lf I know the name of the variable, I can get it's value by name:%din",key);*通过变量key的地址来输出密码值*/printf("lf I know the address of the variable is: %x, then I also can get it'svalue by address: %din",p_addr, *p_addr);return O;1例8-1 利用指针模拟寻找保险箱 密码的过程 获取密码的两种方法 int main(void) { int key = 911; /* 变量key用于存放密码值911 */ int *p_addr = NULL; /* 变量p_addr是整型指针变量 */ p_addr = &key; /* 将key的地址赋给p_addr*/ /* 通过变量key输出密码值*/ printf("The key is: %d\n", key); /* 通过变量名key输出密码值*/ printf("If I know the name of the variable, I can get it’s value by name: %d\n ", key); /* 通过变量key的地址来输出密码值*/ printf("If I know the address of the variable is: %x, then I also can get it’s value by address: %d\n",p_addr, *p_addr); return 0; } If I know the name of the variable, I can get it’s value by name: 911 If I know the address of the variable is:12ff7c, then I also can get it’s value by address: 911
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有