0
WY I get a rundum number from memory when I run this code #include <iostream> using namespace std; int main () { int array [5]; for (int x = 0; x < 5; x++) { array [x] = 42; cout << x << ': ' << array [x] << endl; } return 0; } if I replace ': ' with ": " every thing works well.
don't understand the behavior of cout in this code
2 Answers
+ 2
The ' is for a single character. " for a string. You have two characters ':' and ' ', thus you need double quotes for the string.
+ 2
output will be like this
0: 42
1: 42
2: 42
3: 42
4: 42
and in this every element of array will be 42.
' is for a single character. " for a string. You have two characters ':' and ' ' which make it string, so you need double quote for the string.