I wanted to ask whether the following statement where printf() has been provided with a type int where it expected a type char will invoke UNDEFINED BEHAVIOUR. If not, what exactly is the step will be taken to make it compatible with expected type. Will a be shortened to char type??
int a = 65;
printf("%c", a);
Variable arguments are subject to the default argument promotion, eg
charwill be promoted toint,floattodouble(that’s the reason why you only have a single format specifier to print both single and double precision floating point values).So passing an
intinstead of acharis perfectly valid and even desirable, as character literals are of typeintanyway. According to the C99 spec, section 7.19.6.1 §8, on seeing the conversion specifier%c,printf()expects an argument of typeintand will then go on and cast this value tounsigned char.This means the following is guaranteed to output
a, as conversion of signed to unsigned types is well-defined: