问个C++的结构题目

来源:百度知道 编辑:UC知道 时间:2024/07/02 00:13:11
1:typedef struct x
{
int a;
int b;
}t;
用typedef,它是给struct x取了一个别名叫t;
2:typedef struct
{
int a;
int b;
}t;
而这是一个无名的结构体,是struct 取了一个别名叫t,还是什么取了一个别名叫t???

你说的是对的啊。。。
第一种用typedef,它是给struct x取了一个别名叫t;
第二种是一个无名的结构体,给struct 取了一个别名叫t;
它的定义是
typedef struct
{
int a;
int b;
};
比如:
#include<iostream>
using namespace std;
typedef struct
{
int a;
int b;
}t;
int main()
{

t m;
m.a=1;m.b=2;
cout<<m.a<<" "<<m.b<<endl;
system("pause");
return 0;
}

都差不多,就是以后在定义结构体的时候可以这样: x t;x是结构体类型,t是对象。第二种就不行。

用t代表