I have compiled followin gprogram using GCC compiler on Ubuntu platform.
I am wondering why the following program is working fine in C?
Is it undefined behaviour?
#include <stdio.h>
struct str
{
char arr[0];
};
int main()
{
struct str s;
s.arr[0]=1; // I think it is invalid in C
printf("%d\n", s.arr[0]);
return 0;
}
Output:
1
and when I print printf("%zu\n", sizeof(s));
. it is print 0
.