1

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.

Community
  • 1
  • 1
Shivendra Mishra
  • 638
  • 4
  • 25

2 Answers2

5

q is the array of structure of type p.

p has following elements:

  1. char pointer

  2. any type (int,char,short etc. even a pointer is possible)

  3. pointer to any type

  4. should be a constant

The syntax is actually initializing q[0] and q[1]

Vagish
  • 2,520
  • 19
  • 32
1

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).

tom
  • 354
  • 4
  • 15