C/C++笔试题_3

1.下面程序输出什么:

union
{
    unsigned short s;
    char c[2];
}a;

int main()
{
    a.s = 97;
    printf("%d %d %d\n",a.s,a.c[0],a.c[1]);
    return 0;
}
2.下面代码:

class A
{
public:
    A(){ cout << "构造函数"; }
};

int main()
{
    A a;
    a.A();
    A::A();

    return 0;
}
A.编译错误  B.编译成功,运行错误  C.输出“构造函数构造函数”  D.输出“构造函数构造函数构造函数”

3.下面代码输出什么

union u
{
    struct{
        char a:3;
        char b:3;
        char c:2;
    }s;
    char t;
};
int main()
{
    union u n;
    n.t = 73; //001001001
    printf("%d %d %d %d\n",n.t,n.s.a,n.s.b,n.s.c);

    return 0;
}

4还是代码

#include <stdio.h>
struct bs{
    unsigned a:4;
    unsigned :0; //空域
    char b:4;
    unsigned c:4;
}data;
int main()
{
    printf("%d\n",sizeof(struct bs));
    printf("%d  %d  %d\n",sizeof(data.a),sizeof(data.b),sizeof(data.c));
    //error:'sizeof' applied to a bit-field

    printf("%p\n",&data);
    printf("%p\n",&data.a);//error:cannot take address of bit-field 'a'
    printf("%p\n",&data.b);//error:cannot take address of bit-field 'b'
    printf("%p\n",&data.c);//error:cannot take address of bit-field 'c'

    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值