С结构初始化 [英] С structure initialization

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

问题描述

我怎么能初始化一个结构,如果结构中的一个字段本身就是一个结构?

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 } };

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

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