When I compile it with Borland, the output is 4 2 (which is quite obvious), but when it comes to g++, the output is 4 4. I would understand that if it was a *= a[0];
where modifying a using the reference to a[0] causes undefined behaviour. But in this case a temporary valarray should be created, the items of which are copied into a, shouldn't it? There are sequence points before and after the calls to operator* and operator=, so it's not the problem, either. But it is still executing as if it was