65,211
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <windows.h>
using namespace std;
namespace Jill
{
double bucket(double n)
{
cout <<"bucket = " <<n <<endl;
return n;
}
double fetch;
struct Hill
{
char c;
};
}
char fetch; //globle namespace;
int main()
{
using namespace Jill;
Hill Thill;
double water = bucket(2);
cout <<"water = " <<water <<endl;
double fetch;
cin>>fetch;
cout <<" 1 :fetch" <<fetch <<" , " <<&fetch <<endl;
printf("%p\n",&fetch);
cout <<DWORD(&fetch) <<endl;
cout <<"----------" <<endl;
cin>>::fetch;
cout <<"globle :2 fetch" <<::fetch <<endl;
cout <<&::fetch <<endl;//打印不出全局变量的地址
cout <<"0x"<<hex<<(int)(&::fetch) <<endl; 这样写
ios::sync_with_stdio();
printf("%p\n",&::fetch); //此方法打印全局变量的地址,但是用的 是C的方法
cout <<"--------" <<endl;
cin>>Jill::fetch;
cout <<"3 Jill: " <<Jill::fetch <<"," <<&Jill::fetch <<endl;
system("pause");
return 0;
}
d:\>a
bucket = 2
water = 2
1
1 :fetch1 , 0x22ff60
0022FF60
22ff60
----------
2
globle :2 fetch2
0x446018
446018
00446018
--------
3
3 Jill: 3,0x446010#include <iostream>
#include <windows.h>
using namespace std;
namespace Jill
{
double bucket(double n)
{
cout <<"bucket = " <<n <<endl;
return n;
}
double fetch;
struct Hill
{
char c;
};
}
char fetch; //globle namespace;
int main()
{
using namespace Jill;
Hill Thill;
double water = bucket(2);
cout <<"water = " << hex <<water <<endl;
double fetch;
cin>>fetch;
cout <<" 1 :fetch" <<fetch <<" , " <<&fetch <<endl;
printf("%p\n",&fetch);
cout << hex << DWORD(&fetch) <<endl;
cout <<"----------" <<endl;
cin>>::fetch;
cout <<"globle :2 fetch" <<::fetch <<endl;
cout <<reinterpret_cast<int*>(&::fetch) <<endl;//打印不出全局变量的地址
cout <<hex << DWORD(&::fetch) <<endl; //打印出的是十进制的格式
printf("%p\n",&::fetch); //此方法打印全局变量的地址,但是用的 是C的方法
cout <<"--------" <<endl;
cin>>Jill::fetch;
cout <<"3 Jill: " <<Jill::fetch <<"," <<&Jill::fetch <<endl;
return 0;
}