Posts

Declaring Flexible Array Members in structure

I came across this concept while facing one of my interview then thought to share the concept with you all.It may not seem to be big thing for many of us but sometime prove to be handy while declaring variable arrays in  structure. Any query related to this is highly appreciated. Flexible array members allow incomplete array struct members without bounds . Consider : #include struct flex {     int mem ; // Flex array must have a named member     int arrayWoBoundsSpecified []; // Flex member must be last member }; struct NotAflex {     int a []; // Error: Flex member must be last member                     // Therefore incomplete type should be complete     int mem ; }; int main () {      size_t len = sizeof ( struct flex );     // Flexible array members might be useful for getting variable length information.   ...