C++结构体程序解说。
#include<iostream>
using namespace std;
int main()
struct tree
{
int x;
char *s;
}t;
func(struct tree t)
{
t.x=10;
t.s="computer";
return(0);
}
int main()
{
t.x=1;
t.s="minicomputer";
func(t);
cout<<t.x<<","<<t.s<<endl;
return 0;
}
可以详细解说一下这个程序吗?还有就是这是书本的程序,然后在DEV C++上运行不出结果。
这个就是一个简单的C++程序
其中你的第一个
int main()
是多余的,且是错的,把它删除就可以编译运行了
在main主函数中,首先结结构t赋值,然后调用函数t,而t是作为参数的
在fun中的赋值并不会改全局t的结果
这段程序就是用来演示变量的作用域的
最终结果为
1,minicomputer
热门标签: