struct Structure composite types

struct Structure composite types

struct groups members of different types in declaration order. Use . or ->; padding may make sizeof(struct) exceed the sum of member sizes.

CategoryStruct / Union / Enum
KindKeyword / Statement
C standardC89 / C90

📝 Syntax

struct Point { int x, y; };

▶ Example

Edit the C code below and click Run; the server compiles and executes it:

Output:

sum = 7

📚 Related Tutorials

❓ FAQ

QWhy can a structure's size exceed the sum of its members' sizes?
AAn implementation may insert padding between members and at the end to satisfy alignment requirements for the members and the whole structure. Use sizeof for the actual size and offsetof for member offsets permitted by the standard.
QCan C structures be assigned directly?
AYes. Compatible structure objects can be assigned, copying the value into the destination, including any array members. Pointer members are copied as pointer values, not as the objects they point to, so this is not a deep copy.
QIs struct Point different from Point introduced by typedef?
AIf the typedef names the same struct Point type, the two are simply different names for that type. Structure tags and ordinary identifiers occupy different namespaces, and typedef can make declarations more concise.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏