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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:01:51+00:00 2026-05-16T10:01:51+00:00

Is it possible for code that meets the following conditions to produce different outputs

  • 0

Is it possible for code that meets the following conditions to produce different outputs for each run for the same input?

  • The code is single threaded, though
    it does link against a thread-safe
    runtime library.
  • There are no explicit calls to rand() or time() or their friends.
  • There are some heap memory allocations.
  • There might be some (buggy) code which results in undefined behavior.
  • 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-16T10:01:52+00:00Added an answer on May 16, 2026 at 10:01 am

    “Undefined behavior” means that anything can happen. This also includes that different things might happen on each run of the program.

    For example, if you use uninitialized memory it might be different from program run to program run what exactly that memory contains.

    A simple example:

    int main() {
      char s[1024];
      s[1023] = '\0';
      std::cout << s << std::endl;
    }
    

    This will usually print a different string each time it is run. It doesn’t use any heap allocations and I don’t think it’s even any undefined behavior, so probably it’s not the intended solution to your question.

    Another example would be that new can return different addresses on each program run (also no UB here):

    int main(void) {
       std::cout << new int << std::endl;
    }
    

    So even without undefined behavior there are sources of “randomness”, so certainly also with undefined behavior different things can happen each program run.

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

Sidebar

Related Questions

How is it possible that following code even compiles? As far as I can
Is it possible to transform following code to Linq that it will look like
Is it possible to go back and tie work items to code that's already
Is it possible to write code in a Flex application that will only be
Should I prepare my code for possible/predicted future changes so that it's easier to
is there a possible bit of code (php, java, css, html) that will force
Is it possible that I reserve a asp.net code in db and load it
Is it possible that adding more import statements to your java code could slow
Is it possible to have a piece of code or a function that does
Is it possible to make a Java program that prints its source code to

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.