- 论坛徽章:
- 0
|
- #include <stdio.h>
- #include <string.h>
- typedef struct
- {
- char str[10];
- int a1;
- int a2;
- }st;
- int main()
- {
- st st1;
- strncpy(st1.str, "abcde", 5);
- st1.a1 = 11111111;
- st1.a2 = 22222222;
- printf("[%s], [%d], [%d]\n", st1.str, st1.a1, st1.a2);
- printf("[%s], [%d], [%d]\n", st1.str, st1.a1);
- printf("[%s], [%x], [%x]\n", st1.str, &(st1.a1), &(st1.a2));
- printf("[%s], [%x], [%x]\n", st1.str, &(st1.a1));
- }
复制代码 ///////////////////
结果
[root@liukun8 tmp]# ./a.out
[abcde], [11111111], [22222222]
[abcde], [11111111], [-2068506752]
[abcde], [2ea6d1ac], [2ea6d1b0]
[abcde], [2ea6d1ac], [84b51780]
[root@liukun8 tmp]# ./a.out
[abcde], [11111111], [22222222]
[abcde], [11111111], [-2068506752]
[abcde], [714298bc], [714298c0]
[abcde], [714298bc], [84b51780]
[root@liukun8 tmp]# ./a.out
[abcde], [11111111], [22222222]
[abcde], [11111111], [-2068506752]
[abcde], [3fcd53bc], [3fcd53c0]
[abcde], [3fcd53bc], [84b51780] |
|