Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7767671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:44:02+00:00 2026-06-01T15:44:02+00:00

How can I write (if it’s possible at all…) a function which takes an

  • 0

How can I write (if it’s possible at all…) a function which takes an unknown number of parameters in C99 (the return type is constant)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:44:04+00:00Added an answer on June 1, 2026 at 3:44 pm

    Yes you can do it in C using what are referred to as Variadic Functions.
    The standard printf() and scanf() functions do this, for example.

    Put the ellipsis (three dots) as the last parameter where you want the ‘variable number of parameters to be.

    To access the parameters include the <stdarg.h> header:

    #include <stdarg.h>
    

    And then you have a special type va_list which gives you the list of arguments passed, and you can use the va_start, va_arg and va_end macros to iterate through the list of arguments.

    For example:

    #include <stdarg.h>
    
    int myfunc(int count, ...)
    {
       va_list list;
       int j = 0;
    
       va_start(list, count); 
       for(j=0; j<count; j++)
       {
         printf("%d", va_arg(list, int));
       }
    
       va_end(list);
    
       return count;
    }
    

    Example call:

    myfunc(4, -9, 12, 43, 217);
    

    A full example can be found at Wikipedia.

    The count parameter in the example tells the called function how many arguments are passed. The printf() and scanf() find that out via the format string, but a simple count argument can do it too. Sometimes, code uses a sentinel value, such as a negative integer or a null pointer (see
    execl()
    for example).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How we can write code for onChange function in YUI 2 and YUI3. jQuery(':input[type=radio]').change(function(){
So I know I can write my own HTML-encoding function like this: function getHTMLEncode(t)
How I can write a phone number in the xhtml file and when the
how i can write a closed function for our wpf application in Window application
I can write a function this way in Objective-C. This can be used to
In C# you can write the below and if the type is correct it
As we can write in SQL to return single static value select Jan as
In PHP you can write $arr = array(1,2); list($a, $b) = $arr; Which is
I can write a function like : public function removeRubbishTag(&$aString) Also, I can have
Possible Duplicates: Can you write object oriented code in C? Object Oriented pattern in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.