C Programming Interview Questions – Part 5; What is the size of an empty structure in C?

preview_player
Показать описание
C Programming Interview Questions – Part 5
What is the size of an empty structure in C?

An empty structure is a structure with no members inside it.

In C, the size of an empty structure is not allowed by standard C. Most compilers will show an error if you try to declare or use one.

However, some compilers (like GCC as an extension) may allow it and assign a size of 1 byte to make sure each structure has a unique address in memory.

Why 1 byte?
This is done to ensure that even empty structures take up space in memory and have a unique address, which is useful when structures are part of arrays or used in inheritance in C++.

Conclusion:
In standard C, empty structures are not allowed.
Some compilers may give them a size of 1 byte as an extension.

#cprogramming #embeddedc #embeddedengineer #embeddedinterview #cinterviewquestions #cprogrammer #firmwaredeveloper #cstruct #memorymanagement #codingtips #programminglife #cskills #learnprogramming #cquestions #structureinc #interviewpreparation #techcareers #engineeringstudent #techstudy #jobinterviewtips #softwareinterview #cdevelopment #embeddedlearning #codeconcepts #programmingquestion #codingfacts #lowlevelprogramming #gcc #compilerbehavior
Рекомендации по теме
welcome to shbcf.ru