c++ interesting syntax for printing new line in std::cout
arrays, c++, pointer-arithmetic
Solution
`" \n"` is array of 3 `char`s. You can index is as normal array. Boolean values implicitly convert to integers: `false` to `0`, `true` to `1`. So it will use `'\n'` for `j == 5` and `' '` if not,
Problem
the following code prints a square of `'*'` characters: ``` int m = 5; int n=5; for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) std::cout << "*" << " \n"[j==5]; ``` Output: ``` * * * * * * * * * * * * * * * * * * * * * * * * * ``` My question is regarding to the `" \n"[j==5]` part. Does anyone know how exactly does this syntax work?