C结构初始化? [英] C structure initialization?
本文介绍了C结构初始化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果结构中的一个字段本身就是结构,如何初始化结构?
How can I initialize a structure if one field in the structure is itself a structure?
推荐答案
您需要使用更多的花括号(实际上,它们是可选的,但最近GCC发出警告).这是一个示例:
You need to use more braces (actually, they're optional, but GCC makes a warning these days). Here's an example:
struct s1 { int a; int b; };
struct s2 { int c; struct s1 s; };
struct s2 my_s2 = { 5, { 6, 3 } };
这篇关于C结构初始化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文