Home / C Programming / Variable Number of Arguments :: Discussion

Discussion :: Variable Number of Arguments

  1. Point out the error in the following program.

    
     #include
     #include 
     void display(char *s, ...);
     void show(char *t, ...); 
    
     int main()
     {
         display("Hello", 4, 12, 13, 14, 44);  
         return 0; 
    }
    void display(char *s, ...) 
    {
       show(s, ...); 
     }
     void show(char *t, ...)
     {
         int a;   
         va_list ptr;   
         va_start(ptr, s); 
         a = va_arg(ptr, int);      
         printf("%f", a);
      } 
    

  2. A.

    Error: invalid function display() call

    B.

    Error: invalid function show() call

    C.

    No error

    D.

    Error: Rvalue required for t

    View Answer

    Workspace

    Answer : Option B

    Explanation :

    The call to show() is improper. This is not the way to pass variable argument list to a function.


Be The First To Comment