|
大家好,
最近在面试,被打击了,好多基础都忘记了,做了些实验,希望对大家有所帮助。
- #include <stdio.h>
- typedef enum {
- K1,
- K2
- }exa_enum;
- int main(int argc, char **argv) {
-
- exa_enum hello = 123;
- printf("*********type define specifier size test start ************ \n\n");
- printf( \
- "\tsizeof(int):%d bytes\n"
- "\tsizeof(char):%d bytes\n"
- "\tsizeof(long int):%d bytes\n"
- "\tsizeof(short int):%d bytes\n"
- "\tsizeof(long long int):%d bytes\n"
- "\tsizeof(long double):%d bytes\n"
- "\n", \
- sizeof(int), \
- sizeof(char), \
- sizeof(long int) , \
- sizeof(short int) , \
- sizeof(long long int) , \
- sizeof(long double) \
- );
- printf("*********constant pointer and pointer constant test start ************ \n\n");
- char *str1 = "hello World";
- // char const *ptr1 = str1; // you can also write constant pointer like this
- const char *ptr1 = str1; // constant pointer
- char *str2 = "hello";
- char * const ptr2 = str2; // pointer constant
- // you can't do the following;
- // ptr2 = str1;
- // *ptr1 = 'A';
-
- // you can do the following
- ptr1 = str2;
- str2 = "fuck you!";
- printf("\t ptr1:%s;ptr2:%s\n\n", ptr1, ptr2);
- printf("*********enum size test start ************ \n\n");
-
- printf("\tsizeof(exa_enum):%d bytes\n\tsizeof(hello):%d bytes\n", sizeof(exa_enum), sizeof(hello));
-
- unsigned int array_t[2][3];
- printf("\tarray size %8x , enum value %d\n", array_t, hello);
- return 0;
- }
复制代码
====================================================================================
x86运行结果如下:
PS:编译器GCC
*********type define specifier size test start ************
sizeof(int):4 bytes
sizeof(char):1 bytes
sizeof(long int):4 bytes
sizeof(short int):2 bytes
sizeof(long long int):8 bytes
sizeof(long double):12 bytes
*********constant pointer and pointer constant test start ************
ptr1:hello;ptr2:hello
*********enum size test start ************
sizeof(exa_enum):4 bytes
sizeof(hello):4 bytes
array size bfefbcc8 , enum value 123
====================================================================================
ARM运行结果如下:
PS:编译器,交叉编译工具
*********type define specifier size test start ************
sizeof(int):4 bytes
sizeof(char):1 bytes
sizeof(long int):4 bytes
sizeof(short int):2 bytes
sizeof(long long int):8 bytes
sizeof(long double):8 bytes
*********constant pointer and pointer constant test start ************
ptr1:hello;ptr2:hello
*********enum size test start ************
sizeof(exa_enum):4 bytes
sizeof(hello):4 bytes
array size beb00cf4 , enum value 123
|
阿莫论坛20周年了!感谢大家的支持与爱护!!
你熬了10碗粥,别人一桶水倒进去,淘走90碗,剩下10碗给你,你看似没亏,其实你那10碗已经没有之前的裹腹了,人家的一桶水换90碗,继续卖。说白了,通货膨胀就是,你的钱是挣来的,他的钱是印来的,掺和在一起,你的钱就贬值了。
|