急!! C++ 问题

type="text"

新手上路
VIP
注册
2008-03-05
消息
102
荣誉分数
31
声望点数
0
不知道怎么样display the memory address of the char!code:

#include<iostream>
#include<conio.h>
usingnamespace std;
int main()
{
char type_c;
cout<<
"Address of type_c: "<<&type_c
<<
" size is "<<sizeof(type_c)<<" bytes"<<endl;
return 0;
}
the code above doesn't work ! so any body can help me figure it out
thanks !

output should like this:
Address of char: XXXXXXXXX size is XX bytes
 
一定要用cout吗?printf不行吗?

#include<iostream>
int main()
{
char type_c;
printf(
"Address of type_c: %x, size is %d bytes\n", &type_c, sizeof(type_c));
return 0;
}
实在愿意用cout的话就
#include<iostream>
#include<conio.h>
usingnamespace std;
int main()
{
char type_c;
cout<<
"Address of type_c: "<< hex <<(int)(&type_c)<<" size is "<<sizeof(type_c)<<" bytes"<<endl;
return 0;
}
 
谢谢!!
不过!
printf("Address of type_c: %x, size is %d bytes\n", &type_c, sizeof(type_c));
这个里面的
%x和%d是什么意思啊???
不懂!!
能解释一下吗?

 
你只是DECLARE一个一 char 的VARIABLE type_c;并没有VALUE ASSIGNMENT,在DECLARE的PHASE,,一个VARIABLE 是不会ALLOCATE MEMORY的..
 
try:
cout << (void*)&type_c
you can also use "hex" to specify display an integer in hexadecimal or "dec" for normal decimal, such as
cout << hex << 1234 << dec << 1234;

A real c++ programmer should never use printf
:)
 
productivity is my first concern.
 
这个题目还真热闹啊。
 
后退
顶部