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

  • Home
  • SEARCH
  • 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 6928713
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:13:29+00:00 2026-05-27T11:13:29+00:00

I need to create a function to create a set of integers. As I

  • 0

I need to create a function to create a set of integers. As I don’t know the no. of arguments, I thought of using the ellipses.

   void f1(...)
   {
     va_list ap;
       //how to initialize ap as I don't know the last actual argument as there is no such argument!!!
   }

Also, is there any other way to know whether the list has ended instead of supplying a last argument with a value that denotes the end of list????

Please help!!!

  • 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-05-27T11:13:30+00:00Added an answer on May 27, 2026 at 11:13 am

    Let’s rewrite your function a little.

    Set &f1(int a1, ...)
    {
        Set &new_set = new(Set);
        new_set.add(a1);
        va_list args;
        va_start(args, a1);
        int aN;
        while ((aN = va_arg(args, int)) != -1)
            new_set.add(aN);
        va_end(args);
        return new_set;
    }
    

    Now, this can be invoked with:

    Set s1 = f1(1, -1);
    Set s2 = f1(1, 2, -1);
    Set s3 = f1(1, 2, 3, -1);
    

    Note, though, that the number of arguments is known at each call site. An alternative interface design specifies the number of parameters in the first argument:

    Set s1 = f1(1, 1);
    Set s2 = f1(2, 1, 2);
    Set s3 = f1(3, 1, 2, 3);
    

    However, if you need to specify an arbitrary number of arguments in a single call, then you need an interface more like:

    Set &f1(size_t num, const int *array);
    

    This allows you to specify the number of items in the array.

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

Sidebar

Related Questions

i need to create a function in my application to set its available memory
I need to create a function that uses a loop. This function will open
I need to create a javascript function that checks if it has been a
I need to create a php search function for names and need to change
Need to create a custom DNS name server using C which will check against
I need to create a function that returns a table of continuous dates. I
I've created a stock ticker function and need to call it every 2 minutes.
I need create custom dialog and put JPanel into it. Is it possible?
i need create an email list sending to many emails. what is best solution
I need to create a historical timeline starting from 1600's to the present day.

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.