C语言中的匿名结构体
生活随笔
收集整理的這篇文章主要介紹了
C语言中的匿名结构体
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
在 C 的 C11 標準中,添加了匿名結構和匿名聯合。
匿名聯合/結構也稱為未命名聯合/結構,由于沒有名稱,因此不會創建它們的直接對象(或變量),通常我們在嵌套結構或聯合中使用它們。
An anonymous struct declaration is a declaration that declares neither a tag for the struct, nor an object or typedef name. Anonymous structs are not allowed in C++.
舉例:
// C Program to demonstrate working of anonymous struct #include <stdio.h> struct scope {// Anonymous structurestruct {char alpha;int num;}; };int main(void) {struct scope x;x.num = 65;x.alpha = 'B';// Note that members of structure are accessed directlyprintf("x.alpha = %c, x.num = %d\n", x.alpha, x.num);return 0; }參考資料:
【1】https://www.geeksforgeeks.org/g-fact-38-anonymous-union-and-structure/
【2】https://docs.oracle.com/cd/E19205-01/819-5267/bkael/index.html
總結
以上是生活随笔為你收集整理的C语言中的匿名结构体的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 为什么1900年不是闰年
- 下一篇: mongotemplate模糊查_jav