关于C++指针问题

来源:百度知道 编辑:UC知道 时间:2024/05/17 01:51:17
在C++上看到一个程序
#include <iostream>
using namespace std;
void message(char *msg);
int main ()
{
msssage("hello,world!");
return 0;
}
void message (char *msg)
{
cout<<msg<<endl;
}
运行结果
hello,world!
我 想的是msg是指针 ,为什么输出的是指针所指的对象,而不是输出的指针地址那?请教c++高手了
这是我在全国计算机等级考试二机教程书上看到的程序 在vc++上运行出现错误C:\Documents and Settings\Administrator\123.cpp(6) : error C2065: 'msssage' : undeclared identifier
如上 不知道怎么回事??

#include <iostream>
using namespace std;

int main ()
{
char *msg = "hello, world!";

cout<< msg<< endl;

return 0;
}

相当于这个程序 我是这么想的 还请指教

#include <iostream>
using namespace std;
void message(char *msg);
int main ()
{
msssage("hello,world!");
return 0;
}
void message (char *msg)
{
cout<<&msg<<endl;
}


cout << &msg <<endl;
试试

#include <iostream>
using namespace std;
void message(char *msg);
int main ()
{
msssage("hello,world!");
return 0;
}
void message (char *msg)
{
cout<<(int)msg<<endl;
}
-------------------------------
这样就可以了。