Possible Duplicate:
Array of zero length
I have seen such type of code :-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct pkt {
int pk_type;
int tag;
int magic_num;
char data[0]; <-------- what does this mean ???
}__attribute__((packed));
typedef struct pkt p_t;
int main(void)
{
p_t *p = (p_t *)calloc(1, sizeof(p_t));
if(!p) {
perror("p");
return -1;
}
p->pk_type = 1;
p->tag = 0xb00bbabe;
p->magic_num = 0xcafebabe;
strcpy("hello world", p->data); <-- Seg faults here !!!
return 0;
}
I was wondering the meaning of arr[0]. I mean in what scenarios do we need to use arr[0]. What purpose does it serve?