0
Why does this code print out a number?
#include <iostream> using namespace std; int main() { char zzz = 'z'; for (int i = 0; i< 10; i++) cout << zzz+i; // why does the line output a number? return 0; }
2 Antworten
+ 3
char zzz is implicitly converted to an int when it is added to i.
If you'd like it to output as a char you can cast it to a char.
cout << (char)zzz+i;
0
Got it.
So a character will be converted to its decimal ASCII value when it is added to either an integer or another character.