登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

面包会有的

... ...

 
 
 

日志

 
 

几种结构体定义的区别  

2011-09-17 16:50:30|  分类: H264 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

以下几种结构体定义的区别:
struct {

        int x;

        int y;

} test1;

struct test
{

        int x;

        int y;

}test1;

typedef struct test
{

int x;

int y;

} text1,text2;


typedef struct
{

int x;

int y;

} test1;

 

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

 

(1) 
struct{ 
      int x; 
      int y; 
}test1;   定义了 结构体的对象test1,  test1.x 和 test1.y 可以在语句里用了。    (2) 
struct test {
      int x; 
      int y; 
}test1;   好,定义了 结构test,同时定义了结构体的对象 test1,  test1.x 和 test1.y 可以在语句里用了。  与 (1) 比,省写 了 test    (3)   typedef struct test   {int x; int y;  // 你漏打分号,给你添上   }text1,text2;   只说了 这种结构 的(类型)别名 叫 text1 或叫 text2    真正在语句里用,还要写:  text1 test1;  然后好用 test1.x test1.y    或写 text2 test1;  然后好用 test1.x test1.y    (4)type struct {int x; int y; }test1;  这个不可以。  改 typedef ... 就可以了。  但也同 (3)一样,还要 写:  test1 my_st;  才能用 my_st.x 和 my_st.y
  评论这张
 
阅读(1059)| 评论(0)

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018