初级会员

- 积分
- 70
- 金钱
- 70
- 注册时间
- 2016-7-15
- 在线时间
- 6 小时
|

楼主 |
发表于 2017-2-27 13:28:05
|
显示全部楼层
 
 
#include<iostream> using namespace std; struct student { 
 int id; 
 char name[10];  char zhuanye[20];  }; 
void main() { 
 student stu; 
 cout<<"请输入学生信息:"<<endl;  cout<<"学号:";  cin>>stu.id; 
 cout<<"姓名:";  cin>>stu.name   cout<<"专业:";  cin>>stu.zhuanye;  cout<<endl; 
 cout<<"显示学生信息:"<<endl;  cout<<"学号:"<<stu.id<<endl;  cout<<"姓名;"<<stu.name<<endl;  cout<<"专业:"<<stu.zhuanye<<endl; }  
一、结构体类型变量的定义的两种方法: 1、 先定义结构体类型,再定义结构体变量 
例如,结构体如,定义了struct student 结构体类型,则可以使用该类型来定义一个结构体变量stu. 
Struct student stu;Struct可以省略。 2、 声明结构体类型的同时定义结构体变量 
例如: struct student { 
 int id; 
 char name[10];  char zhuanye[20];  
}stu;  
二、结构体指针变量与结构体变量成员的访问 1、结构体指针变量的定义与初始化 定义格式如下: 
require.async(['wkcommon:widget/ui/lib/sio/sio.js'], function(sio) { var url = 'https://cpro.baidustatic.com/cpro/ui/c.js'; sio.callByBrowser( url, function () { BAIDU_CLB_fillSlotAsync('u2845605','cpro_u2845605'); } ); });
void function(e,t){for(var n=t.getElementsByTagName("img"),a=+new Date,i=[],o=function(){this.removeEventListener&&this.removeEventListener("load",o,!1),i.push({img:this,time:+new Date})},s=0;s< n.length;s++)!function(){var e=n[s];e.addEventListener?!e.complete&&e.addEventListener("load",o,!1):e.attachEvent&&e.attachEvent("onreadystatechange",function(){"complete"==e.readyState&&o.call(e,o)})}();alog("speed.set",{fsItems:i,fs:a})}(window,document);
 
 
结构体数据类型 *变量[=&结构体变量] struct student { 
 int id; 
 char name[10];  char zhuanye[20];  
}stu; 
stu a;*p=&a; 
p为结构体指,指向结构体变量针变量a。&a为结构体变量的指针。   
3、 结构体指针变量对结构体变量成员的引用 格式如下: 
结构体指针变量->所指向的结构体变量的成员 或者: 
(*结构体指针变量). 所指向的结构体变量的成员 例如: Struct  { 
char ch[2]; int x 
}a,*p=&a;  
p->ch[0]; p->ch[1]; p->x; 或者 
(*p).ch[0]; (*p).ch[1]; (*p).x;  |
|