struct hack - zero sized array
#include <iostream> using namespace std; struct node1{ char b[3]; int c[0]; }; struct node2{ int c[0]; }; struct node3{ char b[3]; }; int main() { cout << sizeof(node1) << endl; // prints 4 cout << sizeof(node2) << endl; // prints 0 cout << sizeof(node3) << endl; // prints 3 } My Question is why does the compiler allocate 0 bytes for int c[0] in node2 but allocate 1 byte for its when part of node1. I'm assuming that this 1 byte is the reason why sizeof(node1) returns 4 since without it (like in node3) its size is 3 or is that due to padding?? Also trying to understand that shouldn't node2 have