Functions


  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. View Hint View Answer Discuss in Forum

    NA

    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


  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 = 100, ch2 = 101;
    fun(ch1, ch2);
    return 0;
    }
    int fun(char ch, ...)
    {
    va_list list;
    va_start(list, ch);
    char ch2 = va_arg(list, int);
    printf("%c\n", ch2);
    va_end(list);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    e



  1. What will be the output of the following C code?
    #include <stdio.h>
    #include <stdarg.h>
    int function(int n, ...);
    int main()
    {
    int n = 102;
    float f = 105;
    function(n, f);
    return 0;
    }
    int function(int n, ...)
    {
    va_list list;
    va_start(list, n);
    float f = va_arg(list, float);
    printf("%f\n", f);
    va_end(list);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: E

    Undefined behaviour


  1. Which of the following statements are correct about the following program?
    #include <studio.h>
    int main ( )
    {
    printf ("%p\n", main);
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    Address of main( ) would get printed once.

    Correct Option: E

    Address of main( ) would get printed once.



  1. What error will the following function give on compilation?
    fun(int x, int y )
    {
    int x ;
    y = 54 ;
    return x ;
    }









  1. View Hint View Answer Discuss in Forum

    Re declaration of a.

    Correct Option: C

    Re declaration of a.