博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c 基础系列--- define struct and init struct array
阅读量:6983 次
发布时间:2019-06-27

本文共 1117 字,大约阅读时间需要 3 分钟。

1. struct defination

    struct  _name

 {

         int a;

        char*b;

  ...

    }

 一般之后还要typedef it to let its use be convenient, for example:

    typedef struct _name name;

   or directly write:

   typedef strunct _name

   {

         int a;

        char*b;

  ...  

   }name;

 

2. initialization

    name x={3,"char",...};

 

3. initialize an array of struct:

   name arr[]={

        {1,"xy",...},

        {2,"ab",...},

        ...

                       };

 

The code fragment below demonstrates how to initialize an array of structures within a Microsoft C program. Each element is grouped within brackets, and the elements are separated by commas. The initialization of the array rgttype shows how to initialize a structure within a structure within an array of structures.

/* Compile options needed:  none */ struct stype {
int a; int b; int c; }; struct ttype {
int alpha; struct stype beta; }; /* a, b, c */ struct stype rgstype[2] = { {8, 9, 10}, \ {15, 16, 17} }; /* alpha beta */ struct ttype rgttype[2] = { {
{1}, {2,3,4}}, \ {
{5}, {6,7,8}} };

 

转载地址:http://xivpl.baihongyu.com/

你可能感兴趣的文章
无线加速度传感器
查看>>
设计模式
查看>>
Zend Studio 0x80070666错误解决
查看>>
Mac应用程序无法打开或文件损坏的处理方法
查看>>
网址被微信拦截怎么办 微信屏蔽的域名如何正常访问
查看>>
@ModelAttribute运用详解
查看>>
思科交换机VTP配置
查看>>
正则表达式
查看>>
Mysql中使用命令行导入.sql文件新建数据库表(图文)
查看>>
RUBY有感
查看>>
spring 配置多数据源
查看>>
Java 线程数据交换控制器Exchange使用实例
查看>>
IBM X系列服务器IMM日志采集
查看>>
实验三 静态路由、默认路由配置
查看>>
mysql 查看导出数据字典
查看>>
linux命令--cp
查看>>
到底怎么样才叫看书?
查看>>
python 将ipv4的格式转换
查看>>
C语言宏的副作用的简单实例
查看>>
关于C语言结构体对齐的学习
查看>>