繁体   English   中英

以下声明是什么意思?

[英]What does the following declaration mean?

struct abcd poly[] = {
               {"Inside","Outside"},
               {"Outside","Inside"},
               };

以上声明是什么意思?

这将创建2个名为poly的struct abcd数组。 如果该结构看起来像这样,则将str1和str2设置为“ Inside”和“ Outside”。

struct abcd
{
    const char *str1;
    const char *str2;
};

它是2个结构的数组

struct abcd
{
    char s1[20]; // or *s1
    char s2[20]; // or *s2
};

int main()
{ 
    abcd s[]=  { {"a","b"}, {"c","d"},  };
    cout << s[0].s1<< endl;
    cout << s[0].s2 << endl;
    cout << s[1].s1<< endl;
    cout << s[1].s2 << endl;

}

它是一个由两个元素组成的结构数组。 内括号内的文字初始化结构的字段。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM