single vs double quotes C++ - interesting, unexpected behaviour

54 Views Asked by At

I found some pretty weird behaviour when I was trying to debug my C++ code for an unrelated problem.

I am printing a result at a stage in the program at which I have the integer variables 'amount' and 'coins[i]' as:

std::cout << "Found, 1! n = " <<  amount/coins[i] << " * " << coins[i] << "\n";

However, it makes a difference whether I place the * in double or single quotes. For double quotes, meaning the * is a string, we get:

Found, 1! n = 11 * 1

But for singles we get:

Found, 1! n = 1121079361

What's going on here?

0

There are 0 best solutions below