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

11th Jul 2016, 11:19 PM
zak
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.
12th Jul 2016, 5:08 AM
Tony Christopher
Tony Christopher - avatar
+ 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.
30th Jul 2016, 12:25 AM
shivam kumar
shivam kumar - avatar