sizeof('a')
39 sizeof
2023-09-27 14:26:12 时间
#include <iostream> using namespace std; int main(void) { cout << sizeof('a') << endl; return 0; }
MINGW ,.cpp结果为:1 .c结果为4
VS2013 .c结果为:4 .cpp结果为1
原因:
C99标准的规定,'a'叫做整型字符常量(integer character constant),被看成是int型,所以在32位机器上占4字节。
ISO C++标准规定,'a'叫做字符字面量(character literal),被看成是char型,所以占1字节。
CSDN解释:
https://support.microsoft.com/en-us/kb/150380
CAUSE The specification on this point is different for C from what it is for C++. In C, a character constant is of type int. In C++, a character constant is of type char. Multicharacter constants are implementation dependent. RESOLUTION When using C, do not use sizeof to determine the width of a character constant. Use sizeof("") to give the width of one character in both C and C++.
相关文章
- Tablespace for table '`pomelo`.`bag`' exists. Please DISCARD the tablespace before IMPORT.
- nagios安装check_linux_stats.pl插件报错Can't locate Sys/Statistics/Linux.pm in @INC的处理?
- Error NameError: name 'np' is not defined [closed]
- What is 'typeof define === 'function' && define['amd']' used for?
- _.join(array, [separator=','])
- .Net Core 控制台程序错误:Can not find runtime target for framework '.NETCoreApp,Version=v1.0' compatible with one of the target runtimes: 'win10-x64, win81-x64, win8-x64, win7-x64'.
- Vue-Socket.io跨域问题 has been blocked by CORS policy: No 'Access-Control-Allow-Origin' Mentalflow解决思路
- (转) Don't Panic: Kubernetes and Docker
- Unable to load the mojo 'resources' (or one of its required components) from the plugin......
- 彻底解决:java.sql.SQLException: Incorrect string value: 'xF0x9Fx92x94' for column 'name' at row 1
- 解决ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost:3306' (10061)问题
- Pycharm中出现cannot import name 'AipOcr' from 'aip'或者出现ImportError: cannot import name 'AipFace' from 'aip'解决办法
- java 单元测试 No tests were found 和 org.junit.platform.commons.JUnitException: TestEngine with ID 'junit-jupiter' failed to discover tests
- Let's Encrypt,免费好用的 HTTPS 证书
- 如何解决ubuntu报的错误:You must put some 'source' URIs in your sources.list
- Avoid using implementation types like 'HashMap'; use the interface instead
- SAP MM 带有'Return'标记的STO,不能创建内向交货单?
- org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'PUT' not supported
- The bean 'xx.FeignClientSpecification', defined in null, could not be registered
- Visual Studio® 2010 Web Deployment Projects站点编译生成bin同时发表插件
- 'OFFSET' 附近有语法错误。 在 FETCH 语句中选项 NEXT 的用法无效。(转载)
- Solve error: Cannot open include file: 'X11/Xlocale.h': No such file or directory