It's not printing only a
at all. What you're seeing is instead that cout
prints character type data as characters not as numbers. Your b
is some character that's non-printable so cout
is helpfully printing it as a blank space.
You found the solution by casting it to int.
EDIT: I'm pretty sure your printf is only working by chance because you told it to expect an unsigned int and gave it a character (different number of bytes).