- 论坛徽章:
- 9
|
本帖最后由 mordorwww 于 2017-02-17 17:09 编辑
root@ubuntu:~# vi t.c
//#include <iostream>
#include <stdio.h>
int main()
{
//using namespace std;
int a =8;
const int b =9;
int *p = &a;
//cout<<"addr of a: "<<&a<<endl;
//cout<<"addr of b: "<<&b<<endl;
//cout<<"p = "<<p<<endl;
p++;
//cout<<"p++ ="<<p<<endl;
*p = 0;
printf ("p = %p, *p = %d, &b = %p, b = %d\r\n", p, *p, &b, b);
if (p == &b)
printf ("p == addr of b\r\n");
else
printf ("p != addr of b\r\n");
if (*p == b)
printf ("*p == b\r\n");
else
printf ("*p != b\r\n");
printf ("haha\r\n");
return 0;
}
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"t.c" [New File] 39 lines, 566 characters written
root@ubuntu:~#
root@ubuntu:~#
root@ubuntu:~# g++ t.c -o t
root@ubuntu:~#
root@ubuntu:~#
root@ubuntu:~# ./t
p = 0xbf9c4658, *p = 0, &b = 0xbf9c4658, b = 9
p == addr of b
*p != b
haha
root@ubuntu:~#
root@ubuntu:~# ./t1
p = 0xbfe324e8, *p = 0, &b = 0xbfe324e8, b = 0
p == addr of b
*p == b
haha
root@ubuntu:~#
|
|