c与c++中struct的区别


c语言中,不能直接用结构体名来声明变量。

c++中,可以直接用结构体名来声明变量。

//c语言// //声明 
struct stu
{
    ...
};
//定义 
struct stu student;
//c++//
//声明
struct stu
{
    ...
};
//定义
1.struct stu student;
2.stu student;

如果想在c语言中直接用结构体名定义变量,需要用到 typedef 

//typedef的一般用法
typedef
type new_type;

特别的当type为用户自定义类型时,type 和 new_type 可以相同。

用于结构体时 

typedef struct stu
{
    ...
}Stu;
//定义
1.Stu student;
2.struct stu student;

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM