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;
}