typedef和typedef struct 及#define

#define N  100000

有了这样的定义后,在程序中使用N就代表100000

typedef int word4

给int取个新名字word4

 

(转)struct和typedef struct的 区别

分三块来讲述:
  1 首先://注意在C和C++里不同
    在C中定义一个结构体类型要用typedef:
    typedef struct Student
    {
    int a;
    }Stu;
    于是在声明变量的时候就可:Stu stu1;(如果没有typedef就必须用struct Student stu1;来声明)
    这里的Stu实际上就是struct Student的别名。Stu==struct Student
    另外这里也可以不写Student(于是也不能struct Student stu1;了,必须是Stu stu1;)
    typedef struct
    {
    int a;
    }Stu;
    但在c++里很简单,直接
    struct Student
    {
    int a;
    };    
    于是就定义了结构体类型Student,声明变量时直接Student stu2;
===========================================

  2.其次:
    在c++中如果用typedef的话,又会造成区别:
    struct   Student   
    {   
    int   a;   
    }stu1;//stu1是一个变量  

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

 
    使用时可以直接访问stu1.a
    但是stu2则必须先   stu2 s2;
    然后               s2.a=10;
==========================================

原文链接: https://www.cnblogs.com/zhangxiujun/p/3931561.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    typedef和typedef struct 及#define

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/143166

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月11日 上午9:11
下一篇 2023年2月11日 上午9:14

相关推荐