• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
July 08, 2022 |2.5K Views
Struct hack
  Share   Like
Description
Discussion

In gcc, when we create an array of zero length, it is considered as array of incomplete type that’s why gcc reports its size as “0” bytes. This technique is known as “Struct Hack”. When we create array of zero length inside structure, it must be (and only) last member of structure. Shortly we will see how to use it. 


“Struct Hack” technique is used to create variable length member in a structure. In the above structure, string length of “name” is not fixed, so we can use “name” as variable length array.


Struct hack   : https://www.geeksforgeeks.org/struct-hack/