您现在的位置: 中国男护士网 >> 考试频道 >> 计算机等级 >> 二级辅导 >> C语言 >> 辅导 >> 正文    
  c语言中长度为0的数组妙用 【注册男护士专用博客】          

c语言中长度为0的数组妙用

www.nanhushi.com     佚名   不详 

  长度为0的数组在GNU C是可以使用的,考试大首发在定义一个变长对象的结构体是非常有用的。
  请看下例。
  struct line {
  int length;
  char contents[0];
  };
  struct line *thisline = (struct line *)
  malloc (sizeof (struct line) + this_length);
  thisline->length = this_length;
  Examda提示:显然这样的代码要比下面的定义节省空间
  struct line {
  int length;
  char *contents;
  };
  struct line {
  int length;
  char contents[1];
  };

 

文章录入:杜斌    责任编辑:杜斌 
  • 上一篇文章:

  • 下一篇文章:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
     

    联 系 信 息
    QQ:88236621
    电话:15853773350
    E-Mail:malenurse@163.com
    免费发布招聘信息
    做中国最专业男护士门户网站
    最 新 热 门
    最 新 推 荐
    相 关 文 章
    没有相关文章
    专 题 栏 目