struct和typedef struct

转自:http://www.cnblogs.com/qyaizs/articles/2039101.html

 一、C与C++不同

C用结构体声明变量的时候必须加struct,而C++不需要

struct Student
{
  int a;
}; 
C语言 声明 struct Student stu1;
C++ 声明  (struct) Student stu2;

所以C语言定义结构体时使用typedef

typedef struct Student
{
  int a;
}Stu;
这样Stu是struct Student的别名,Stu==struct Student,声明变量时使用Stu就可以了,方便简洁

二、C++使用typedef区别

struct   Student  
{   
   int   a;   
}stu1;//stu1是一个变量  

 
typedef   struct   Student2  
{   
   int   a;   
}stu2;//stu2是一个结构体类型=struct Student

 

posted @ 2018-03-07 16:44  蓝天飞翔的白云  阅读(169)  评论(0编辑  收藏  举报