I looked over but couldn't find a decent answer.
I was wondering how printf works in case like this:
char arr[2] = {5,6};
printf ("%d%d",arr[0],arr[1]);
I was thinking that printf just walks through the format and when it encouter %d for example it reads 4 bytes from the it's current position... however that's gotta be misconcepition cause that above works perfectly.
so, where am I wrong ?
You're right. But there's argument promotion that converts (among other things) your char
:s into int
:s when they are used with a "varargs" function like printf()
.
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