main() {
unsigned int a=-9;
printf("%d",a);//gives output -9
cout<<a;// gives output 9429967287
getch();
}
Why it gives different output in both cases?
Do 'printf' and 'cout' treat bit pattern in a different way?
Why is 'printf' not giving the positive answer?
Because you told it to: %d is for printing an argument as a signed int. To print an unsigned int, you should have used %u.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With