I am not understanding how c1 is printing 65, 66, 67, 68. I know how char c is printing A B C D, but how c1 has strange output?
#include<stdio.h>
#include<stdarg.h>
void display(int num, ...);
int main()
{
display(4, 'A', 'B', 'C', 'D');
return 0;
}
void display(int num, ...)
{
char c, c1; int j;
va_list ptr, ptr1;
va_start(ptr, num);
va_start(ptr1, num);
for(j=1; j<=num; j++)
{
c = va_arg(ptr, int);
printf("%c", c);
c1 = va_arg(ptr1, int);
printf("%d\n", c1);
}
}
It is not a strange output. You have mentioned the format specifier as "%d" in printf("%d\n", c1);
. "%d" is the integer format specifier. So, the variable c1 is implicitly typecasted to an integer i.e ASCII value of the character. So in your case, it prints 'A' as 65, 'B' as 66 etc.
Refer to Conversion specifiers topic in fprintf()