初始化一个结构的Struct [英] Initializing a Struct of a Struct

查看:128
本文介绍了初始化一个结构的Struct的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在C结构具有的整数,阵列,如何初始化整数0和阵列的为0的第一要素,如果该结构是一个部件另一结构,使得对于每一个实例其他结构的整数数组有那些初始化值?

If I have a struct in C that has an integer and an array, how do I initialize the integer to 0 and the first element of the array to 0, if the struct is a member another struct so that for every instance of the other struct the integer and the array has those initialized values?

推荐答案

Initialisers可以嵌套嵌套结构,例如

Initialisers can be nested for nested structs, e.g.

typedef struct {
    int j;
} Foo;

typedef struct {
    int i;
    Foo f;
} Bar;

Bar b = { 0, { 0 } };

这篇关于初始化一个结构的Struct的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆