创新工场一道笔试题

来源:互联网 发布:风云无双天罪进阶数据 编辑:程序博客网 时间:2024/04/29 10:15
#include <stdio.h>union A{int i;char c[2];};int main(){union A t;t.c[0] = 10;t.c[1] = 1;printf("%d", t.i);return 0;}


这个程序输出是什么?

(gdb) l8    9    int main(int argc, const char *argv[])10    {11        union A t;12        13        t.c[0] = 10;14        t.c[1] = 1;15    16        printf("%d\n", t.a);17        return 0;(gdb) b 13Note: breakpoint 2 also set at pc 0x100000f07.Breakpoint 3 at 0x100000f07: file test.c, line 13.(gdb) rStarting program: /Users/lee/MyProgram/test/test Breakpoint 2, main (argc=1, argv=0x7fff5fbff9d0) at test.c:1313        t.c[0] = 10;(gdb) p t$5 = {  a = 1606416824,   c = "??"}(gdb) x/4xb &t0x7fff5fbff9a0:    0xb8    0xf9    0xbf    0x5f(gdb) n14        t.c[1] = 1;(gdb) p t$6 = {  a = 1606416650,   c = "\n?"}(gdb) x/4xb &t0x7fff5fbff9a0:    0x0a    0xf9    0xbf    0x5f(gdb) n16        printf("%d\n", t.a);(gdb) p t$7 = {  a = 1606353162,   c = "\n\001"}(gdb) x/4xb &t0x7fff5fbff9a0:    0x0a    0x01    0xbf    0x5f(gdb) n1606353162


原创粉丝点击