NetApp Interview Question
Software Engineer / DevelopersIt is used to explicitly force data alignment for the variables declared next. This is used mostly as element in the structure to force alignment and less outside struct/union. Any definition following this a[0] is guaranteed to be aligned on 4-byte address instead of its natural alignment requirement.
int a[0]
can be used to describe a variable-length field of a structure. For example, consider:
struct Foo {
int x;
int y;
int a[0];
};
If I want a to be 10 bytes, I could do:
struct Foo *f = malloc(sizeof(struct Foo) + 10);
If I want a to be 20 bytes, I could do:
struct Foo *f = malloc(sizeof(struct Foo) + 20);
cannot allocate an array of constant size 0
- manu October 01, 2010