//结构指针变量的声名和使用示例

//结构指针变量的声名和使用示例 
#include<iostream.h>
#include<conio.h>

struct student
{
   int num;
   char name[20];
   char sex;
   float score;       
       
       
} ;

int main()
{
  student stud={120,"weishanshan",'N',92};
  student *pstud=&stud;
  //通过结构变量访问结构的成员
       cout<<"Access structure through structure variable:\n";
       cout<<"num="<<stud.num<<"\t";
       cout<<"name="<<stud.name<<"\t"; 
       cout<<"sex="<<stud.sex<<"\t";
       cout<<"score="<<stud.score<<endl<<endl;   
   
   //通过指针访问结构,使用圆点运算符结构的成员(*^__^*) 
       cout<<"Access structure through pointer and (.) variable:\n";
       cout<<"num="<<(*pstud).num<<"\t";
       cout<<"name="<<(*pstud).name<<"\t"; 
       cout<<"sex="<<(*pstud).sex<<"\t";
       cout<<"score="<<(*pstud).score<<endl<<endl;    
   //通过指针访问结构,使用箭头运算符     
       cout<<"Access structure through pointer and (->) variable:\n";
       cout<<"num="<<pstud->num<<"\t";
       cout<<"name="<<pstud->name<<"\t"; 
       cout<<"sex="<<pstud->sex<<"\t";
       cout<<"score="<<pstud->score<<endl<<endl;   
           
  getch();
  return 0;         
           
} 
 

你可能感兴趣的:(float,structure)