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 8068823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:49:01+00:00 2026-06-05T12:49:01+00:00

I started writing this code a few days ago. I saw a question on

  • 0

I started writing this code a few days ago. I saw a question on here that got me wondering about variable argument lists, so I wrote (never really finished, but it has the functionality I was curious about) this piece of code:

void VendingMachine::setStamps(int largest, ...)
{
   cout << "Setting stamps to: \n";
   vector<int> tmp;
   vector<int>::iterator iter;
   int next = largest;
   va_list lst;
   va_start(lst, largest);
   while(next != NULL)
   {
      cout << next << "\n";
      tmp.push_back(next);
      next = va_arg(lst,int);
   }
   va_end(lst);

   stamps = new int[tmp.size()-1];

   int i = 0;
   for(iter = tmp.begin(); iter != tmp.end();)
   {
      stamps[i] = *iter;
      iter++;
      i++;
   }

   cout << "The array is now: ";
   showStamps();
}

void VendingMachine::showStamps()
{
   cout << sizeof(stamps) << " " << sizeof(*stamps);
   for(int i = 0; i < NUM_OF(stamps); i++)
      cout << stamps[i] << ", ";
   cout << "\n";
}

Now, what I’d expect is for setStamps to never finish. Or at least take a very long time, and a variable amount of time, since no part of the list is guaranteed to be NULL unless it was supplied. This isn’t the case. I call setStamps with v.setStamps(90,30,24,15,12,10,5,3,2,1); and it prints this out:

Setting stamps to:
90
30
24
15
12
10
5
3
2
1
-217832717
The array is now: 4 490,

Ignoring the last line, since that was me messing around trying to figure out how to determine the length of an array, this doesn’t make sense. It stopped after the first value that was outside of the passed arguments. It should have kept going until there was a NULL value, and there shouldn’t be one of those in the same place each time. But the outcome is always the same: 90, 30, 24, 15, 12, 10, 5, 3, 2, 1, [number that changes each time]. There’s never any additional values. It’s a mystery.

  • 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-05T12:49:03+00:00Added an answer on June 5, 2026 at 12:49 pm

    and there shouldn’t be one of those in the same place each time

    Who says there won’t be one in the same place every time? The behavior is undefined, and so having a NULL value in the same place every time is entirely possible.

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

Sidebar

Related Questions

I started writing a very Simple jQuery Popup myself. Here is the code <script
I have started writing a Macro in Visual Studio 2005 like this: Public Sub
I'm just getting started on writing functions instead of writing everything inline. Is this
I've just started writing a reasonably straightforward site using sinatra. My problem is that
I have just installed C# 2008 Express Edition 2008 and started writing code. My
This started out as a general user question on Android forums. However it's become,
I'm writing some C++ code that will have to send data over TCP/IP. I
I've got a MVC3 website that I've just started. I'd like to add logging
A few weeks ago I started my first project with TDD. Up to now,
I am writing this little python program that will get new posts on the

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.