【发布时间】:2013-04-09 12:46:05
【问题描述】:
如何打印用户输入的地址?这种方式行不通。
这是代码。谢谢。
#include <iostream>
using namespace std;
int main()
{
int num = 123456;
int *addr = #
cout << "Var: num, address: " << &num << ", has: " << num << endl
<< "Var: *addr, address: " << &addr << ", has: " << addr << endl
<< "Printing value of num using the pointer *addr: " << *addr << endl;
int addr_user;
cout << "Type the memory address: "; cin >> addr_user;
int *p_addr_user = (int *)addr_user;
cout << "The address given (" << addr_user << ") has: " << *p_addr_user << endl;
return( 0 );
}
对不起,我不是很清楚:
程序必须做什么: 要求输入一个整数,从这些整数中打印内存地址,要求输入上面打印的内存地址,打印该内存地址的内容并确认该地址是否具有在第一步中输入的数字。
一站式运行。提前谢谢你。
【问题讨论】:
-
啊,对不起,我第一次没有理解你的要求,所以我的回答根本不是你要找的:)