[英]Why my code is giving different output by just commenting a single printing cout statement in c++?
[英]explanations of the code here, order of output in cout statement in c++
#include<iostream>
using namespace std;
int main(){
char c = 'a';
int numb;
for (int i = 1; i <= 25 ; i++){
cout << c << "," << c++ << endl;
}
}
為什么當我打印上面的輸出時,會打印以下內容:
b,a
c,b
d,c
但我期待:
a,b
b,c
c,d
我相信這與這里的操作順序有關。 流運算符 ( <<
) 從右到左操作。 這意味着在第一次運行中, c++
計算結果為“a”,但導致c
迭代到“b”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.