sizeof直接常量时候c/c++解释不同-创新互联
见代码:
#include#includeint main(void){//直接常量时候c/c++解释不同
printf("%lu\n",sizeof 'a');//4(c) 1(c++)
//之后的c/c++解释相同
printf("%lu\n",sizeof "a");//2
char a = 'a';
const char *pa = "a";
printf("%lu\n",sizeof a);//1
printf("%lu\n",sizeof pa);//8
printf("%lu\n",sizeof 100);//4
printf("%lu\n",sizeof 100L);//8
return EXIT_SUCCESS;
}
编译环境:
root@DESKTOP-BE054DB:/mnt/i# gcc --version
gcc (Ubuntu 9.4.0-1ubuntu1~20.04) 9.4.0
Copyright © 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
root@DESKTOP-BE054DB:/mnt/i# g++ --version
g++ (Ubuntu 9.4.0-1ubuntu1~20.04) 9.4.0
Copyright © 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧
本文名称:sizeof直接常量时候c/c++解释不同-创新互联
网站地址:http://ybzwz.com/article/psooj.html