小编red*_*b17的帖子

工会不能正常工作

这是我的代码.它适用于C,但它的行为类似于C++中的结构.

#include<iostream>
using namespace std;
int main()
{
    union myunion
    {
        int B;
        double PI;
    };

    union myunion numbers;
    numbers.PI = 3.14;
    numbers.B = 12; 

    /* now storage of PI should be over-written */

    cout<<numbers.PI<<endl;
    cout<<numbers.B<<endl;

    /* Output is  3.14 */
    /*            12   */
    /* Why it is behaving like Structures ? */
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ storage structure unions data-structures

1
推荐指数
1
解决办法
328
查看次数

标签 统计

c++ ×1

data-structures ×1

storage ×1

structure ×1

unions ×1