Why in the code “456”+1, output is “56”
Question:
#include <iostream>
int main()
{
std::cout << "25"+1;
return 0;
}
I am getting "5" as output.when I use "5"+1,output is blank;"456"+1 output is "56".confused what is going behind the scenes.
Answer:
The string literal "25" is really a char array of type const char[3] with values {'2', '5', '\0'} (the two characters you see and a null-terminator.) In C and C++, arrays can easily decay to pointers to their first element. This is what happens in this expression:
"25" + 1
where "25" decays to &"25"[0], or a pointer to the first character. Adding 1 to that gives you a pointer to 5.
On top of that, std::ostream, of which std::cout is an instance, prints a const char* (note that char* would also work) by assuming it is a null-terminated string. So in this case, it prints only 5.
Why in the code “456”+1, output is “56”的更多相关文章
- svn Error: post-commit hook failed (exit code 127) with output
Command: Commit Modified: C:\Users\xsdff\Desktop\project\index.html Sending content: C:\Users\xsdff\ ...
- svn 提交报错post-commit hook failed (exit code 23) with output
svn 提交文件,hook同步更新报权限错误 排查后可能原因是被同步的服务器 selinux 已开启. 查看状态命令:/usr/sbin/sestatus -v #如果SELinux status参 ...
- SVN提交时报错:Commit blocked by pre-commit hook (exit code 1) with no output.
可能的原因: 提交代码的SVN命令中,Comment长度短了.参考:http://tortoisesvn.net/docs/nightly/TortoiseSVN_en/tsvn-howto-minl ...
- java io读书笔记(5) Writing Bytes to Output Streams
outputstream类是所有的字符输出类的父类,他是一个抽象类. 对于OutputStream类来说,其最基础的方法就是:write(). public abstract void write(i ...
- Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) A B C D 水 模拟 并查集 优先队列
A. Broken Clock time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- The secret code
The secret code Input file: stdinOutput file: stTime limit: 1 sec Memory limit: 256 MbAfter returnin ...
- MySQL下perror工具查看System Error Code信息
在MySQL数据库的维护过程中,我们有时候会在MySQL的错误日志文件中看到一些关于Operating system error的错误信息,例如在MySQL的错误日志里面,有时候会看到关于 Inn ...
- Hadoop Exit Code 含义
经常遇到的exception是: 1. PipeMapRed.waitOutputThreads(): subprocess failed with code N ............ 2. T ...
- hive subprocess failed with code X 的错误码对应信息
PipeMapRed.waitOutputThreads(): subprocess failed with code X ,这里code X对应的信息如下:error code 1: Operati ...
随机推荐
- noip第21课资料
- Beta冲刺 (7/7)
Part.1 开篇 队名:彳艮彳亍团队 组长博客:戳我进入 作业博客:班级博客本次作业的链接 Part.2 成员汇报 组员1:(组长)柯奇豪 过去两天完成了哪些任务 部分代码的整合 编辑文章部分的完成 ...
- IDEA运行android项目一直是同一个apk
1.IDEA运行android项目时不像eclipse和android studio那样直接运行,IDEA需要设置Artifacts,这样每次运行的时候它才能重新编译,以下附上步骤! 这样就可以了.
- RunC容器逃逸漏洞席卷业界,网易云如何做到实力修复?
近日,业界爆出的runC容器越权逃逸漏洞CVE-2019-5736,席卷了整个基于runC的容器云领域,大量云计算厂商和采用容器云的企业受到影响.网易云方面透露,经过技术团队的紧急应对,网易云上的容器 ...
- 【BZOJ4025】 二分图(线段树分治)
传送门 BZOJ Solution 只是为了学习一下线段树分治的啦! 当你学会线段树分治之后,可以跳过下面的一部分: 按照时间搞一颗线段树出来,把包含这段区间的操作用vector压进去. 每一个线段树 ...
- 「ZJOI2018」胖(ST表+二分)
「ZJOI2018」胖(ST表+二分) 不开 \(O_2\) 又没卡过去是种怎么体验... 这可能是 \(ZJOI2018\) 最简单的一题了...我都能 \(A\)... 首先我们发现这个奇怪的图每 ...
- 开源播放器 ijkplayer (四) :Ijkplayer切换网络时停止播放的问题处理
问题起因: 在进行ijkplayer播放器的测试时,发现ijkplayer播放器在切换网络时出现直播画面停止的问题. 问题分析: 抓取日志发现:tv.danmaku.ijk.media.player. ...
- Appium同时连接多台手机进行测试(多线程)
作为测试小白,当时遇到了N多问题: 开启多线程后,发现app启动后,用例就停止了:且启动app对应的手机不能正确对应,用例中是A手机跑A用例,结果启动了B手机跑A用例报错. 主要原因:Appium S ...
- python numpy安装
一.python下的numpy安装方法 第一步:安装python,这里不做介绍. 第二步:打开cmd看python是否安装成功. 第三步:输入 python -m pip install -U pip ...
- 【WebAPI No.2】如何WebAPI发布
介绍: Asp.Net Core在Windows上可以采用两种运行方式.一种是自托管运行,另一种是发布到IIS托管运行. 自托管 首先有一个完好的.Net Core WebAPI测试项目,然后进入根目 ...