Reputation: 688
What are the different syntax of c structure? How do decode this :
struct p {
char a[1];
int b;
int *a;
int value;
};
struct p q[] = {
{"a", 0, &b, C},
{"J", 0, &k, l}
};
I found a another discussion here but didn't encounter this type.
Upvotes: 1
Views: 146
Reputation: 354
That is declaring an array called q of type struct p, it is not actually defining a struct at all. The {"a", 0, etc...}'s inside the initialization list are creating the structs that populate the first and second element of the array by defining values for the structs fields, and in doing so, creating instances of the struct on the stack.
struct p appears to contain a char*,
an integer,
some other pointer
and something else(probably an integer).
Upvotes: 1
Reputation: 2547
q
is the array of structure of type p
.
p
has following elements:
char pointer
any type (int,char,short etc. even a pointer is possible)
pointer to any type
should be a constant
The syntax is actually initializing q[0]
and q[1]
Upvotes: 5