定义一个结构体变量stu,成员包括学号,姓名,性别,成绩,定义一个指针变量p指向该结构体变量stu

定义一个结构体变量stu,成员包括学号,姓名,性别,成绩,定义一个指针变量p指向该结构体变量stu,通过该指针变量输出各成员的值

第1个回答  2015-03-30
#include <iostream>
#include <string>
using namespace std;
int main( )
{
struct Student
{
int num;
string name;
char sex;
float score;
};
Student stu;
Student *p=&stu;
stu.num=10001;
stu.name="KYO";
stu.sex='F';
stu.score=89.5;
cout<<p -> num<<" "<<(*p).name<<" "<<(*p).sex<<" "<<(*p).score<<endl;
return 0;
}追问

不好意思 发错了

追答

定义结构体struct student后面不能加分号 它不是一句完整的语句

追问

对的 谢谢你

本回答被提问者和网友采纳
相似回答