Kitcha
Kitcha

Reputation: 1731

What does the following declaration mean?

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

What does the above declaration mean?

Upvotes: 0

Views: 147

Answers (3)

haberdar
haberdar

Reputation: 511

It is an array of 2 structs

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;

}

Upvotes: 2

NPE
NPE

Reputation: 500367

It's a two-element array of structs. The literals inside the inner braces initialize the structs' fields.

Upvotes: 0

Joe
Joe

Reputation: 57179

That will create an array of 2 struct abcd named poly. If the struct looks like this then str1 and str2 would be set to "Inside" and "Outside".

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

Upvotes: 4

Related Questions