-
What will be the output of the following C code?
#include <stdio.h>
#include <stdarg.h>
int fun(char ch, ...);
int main()
{
char ch1 = 99, ch2 = 100;
fun(ch1, ch2);
return 0;
}
int fun(char ch, ...)
{
va_list list;
va_start(list, ch1);
char ch2 = va_arg(list, char);
printf("%c\n", ch2);
va_end(list);
}
-
- c
- Compilation Error
- d
- Undefined behaviour
- None of these
Correct Option: D
Compilation Error
In file included from main.c:2:0:
main.c: In function ‘fun’:
main.c:13:24: error: ‘ch1’ undeclared (first use in this function); did you mean ‘ch’?
va_start(list, ch1);
^
main.c:13:24: note: each undeclared identifier is reported only once for each function it appears in
main.c:14:33: warning: ‘char’ is promoted to ‘int’ when passed through ‘...’
char ch2 = va_arg(list, char);
^
main.c:14:33: note: (so you should pass ‘int’ not ‘char’ to ‘va_arg’)
main.c:14:33: note: if this code is reached, the program will abort