Home » C Programming » Functions » Question
  1. 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);
    }
    1. c
    2. Compilation Error
    3. d
    4. Undefined behaviour
    5. 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



Your comments will be displayed only after manual approval.