赞
踩
C语言非常之经典的笔试题。
- void checkCpuMode(void)
- {
- int c = 0x12345678;
- char *p = (char *)&c;
- if(p[0] == 0x12)
- printf("Big endian.\n");
- else if(p[0] == 0x78)
- printf("Little endian.\n");
- else
- printf("Uncertain.\n");
- }
- void checkCpuMode(void)
- {
- int c = 0x12345678;
- char *p = (char *)&c;
- if(*p == 0x12)
- printf("Big endian.\n");
- else if(*p == 0x78)
- printf("Little endian.\n");
- else
- printf("Uncertain.\n");
- }
- void checkCpuMode(void)
- {
- union Data
- {
- short a;
- char b[sizeof(short)];
- }data;
- data.a = 0x1234;
- if(data.b[0] == 0x12)
- printf("Big endian.\n");
- else if(data.b[0] == 0x34)
- printf("Little endian.\n");
- else
- printf("uncertain.\n");
- }
- #include<stdio.h>
- #include<stdlib.h>
- #include<string.h>
- void getmemory(char *p)
- {
- p = (char *)malloc(100);
- strcpy(p, "hello world");
- }
- int main()
- {
- char *str = NULL;
- getmemory(str);
- printf("%s\n", str);
- free(str);
- return 0;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。