Variadic functions in C

Sort by

recency

|

141 Discussions

|

  • + 0 comments
    also using the dynamic memory allocation
    
    int  sum (int count,...) {
        int sumx =0;
        va_list listt;
        va_start(listt,count);
        
        for(int i = 0 ;i<count;i++){
            sumx += va_arg(listt,int);
            
        }
        va_end(listt);
        return sumx;
    }
    
    int min(int count,...) {
        int* least_count;
        int intialleast = 0;
        least_count= (int*)malloc(count*(sizeof(int)));
        va_list listt;
        va_start(listt,count);
        
        for(int i = 0;i<count;i++){
            least_count[i] = va_arg(listt,int);
            if(least_count[i] <= intialleast){
                intialleast = least_count[i];
            }
        }
        va_end(listt);
        free(least_count);
        least_count = NULL;
        
        return intialleast;
    }
    
    int max(int count,...) {
        int* max_count;
        int intialleast = 0;
        max_count= (int*)malloc(count*(sizeof(int)));
        va_list listt;
        va_start(listt,count);
        
        for(int i = 0;i<count;i++){
            max_count[i] = va_arg(listt,int);
            if(max_count[i] >= intialleast){
                intialleast = max_count[i];
            }
        }
        va_end(listt);
        free(max_count);
        max_count = NULL;
        
        return intialleast;
    }
    
  • + 0 comments

    Great explanation! Variadic functions are such a powerful feature in C, giving developers the flexibility to handle different numbers of arguments without rewriting multiple function overloads. play exchange

  • + 0 comments

    This is a great challenge for anyone looking to improve their understanding of C programming! Variadic functions are a powerful feature, Dentist near me

  • + 0 comments

    This is a clear and practical explanation of variadic functions in C, and it nicely shows how they can make programs more flexible. Cricbet99

  • + 0 comments

    Here is Variadic functions in C solution - https://programmingoneonone.com/hackerrank-variadic-functions-in-c-problem-solution.html