下面关于"联合"的题目的输出是什么
编辑: 面试啦 发布时间: 2023-10-21 10:15:48
a)
#i nclude
union
{
int i;
char x[2];
}a;
void main()
{
a.x[0] = 10;
a.x[1] = 1;
printf(“%d”,a.i);
}
答案:266 (低位低地址,高位高地址,内存占用情况是Ox010A)
b)
main()
{
union{ /*定义一个联合*/
int i;
struct{ /*在联合中定义一个结构*/
char first;
char second;
}half;
}number;
number.i=0×4241; /*联合成员赋值*/
printf(“%c%c\n”, number.half.first, mumber.half.second);
number.half.first=’a'; /*联合中结构成员赋值*/
number.half.second=’b';
printf(“%x\n”, number.i);
getch();
}
答案: AB (0×41对应’A',是低位;Ox42对应’B',是高位)
6261 (number.i和number.half共用一块地址空间)
#i nclude
union
{
int i;
char x[2];
}a;
void main()
{
a.x[0] = 10;
a.x[1] = 1;
printf(“%d”,a.i);
}
答案:266 (低位低地址,高位高地址,内存占用情况是Ox010A)
b)
main()
{
union{ /*定义一个联合*/
int i;
struct{ /*在联合中定义一个结构*/
char first;
char second;
}half;
}number;
number.i=0×4241; /*联合成员赋值*/
printf(“%c%c\n”, number.half.first, mumber.half.second);
number.half.first=’a'; /*联合中结构成员赋值*/
number.half.second=’b';
printf(“%x\n”, number.i);
getch();
}
答案: AB (0×41对应’A',是低位;Ox42对应’B',是高位)
6261 (number.i和number.half共用一块地址空间)
词条:c面试题
面试题库导航
- C++面试题
- JAVA面试题
- Oracle面试题
- MySQL面试题
- Linux面试题
- 网络工程师面试题
- 网管面试题
- 软件工程师面试题
- PHP面试题
- .net面试题
- 软件测试面试题
- EJB面试题
- Spring面试题
- Javascript面试题
- Python面试题
- QTP面试题
- Servlet面试题
- J2EE面试题
- Database面试题
- ASP面试题
- Unix面试题
- Loadrunner面试题
- 通信面试题
- 嵌入式面试题
- Ruby面试题
- Delphi面试题
- Mobile开发面试题
- SOA面试题
- JAVA面试题面试题
- 研发工程师面试题
- 软件架构师面试题
- 系统工程师面试题
- Android面试题
- JAVA程序员
- C#面试题