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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:38:07+00:00 2026-05-27T17:38:07+00:00

I have a windows form application built using VC++ dot net 3. There is

  • 0

I have a windows form application built using VC++ dot net 3.
There is a integer variable say int x.

When I run the application in debug mode the value for x =0;
But when I run the application without debugging the value is huge 113901996.

The variable is initialzed as int x = 0

Why is this so? Some setting I need to check?

  • 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-27T17:38:08+00:00Added an answer on May 27, 2026 at 5:38 pm

    EDIT: As per your new info, that you’re forgetting to initialize the variable, the behavior is expected. You’re reading garbage memory.

    Now, even if you did initialize the variable, you could still replicate this behavior by not using it in a manner that affects the observable behavior of the program. This is what my original answer treated – which I will leave here for future reference.

    Are you actually using x? If you’re just initializing it, the optimizer will most likely exclude the whole thing.

    If it’s not influencing the observable behavior of the program, the optimizer is free to cut anything from the binary.

    The watch might also be lying to you, I’ve seen that happening in Release mode.

    Can you post some minimal code that reproduces the problem?

    If you test it with some output, i.e. :

    cout << x;
    

    I’m sure you’ll see that x is 0.

    EDIT:

    Just to clear things out:

    int main()
    {
       int x = 0;
       x = 3;
       return 0;
    }
    

    will translate to (in release mode, with full optimization):

    00401000  xor         eax,eax 
    00401002  ret  
    

    The variable not only isn’t assigned, it doesn’t even exist; as opposed to the debug version:

    00411370  push        ebp  
    00411371  mov         ebp,esp 
    00411373  sub         esp,0CCh 
    00411379  push        ebx  
    0041137A  push        esi  
    0041137B  push        edi  
    0041137C  lea         edi,[ebp-0CCh] 
    00411382  mov         ecx,33h 
    00411387  mov         eax,0CCCCCCCCh 
    0041138C  rep stos    dword ptr es:[edi] 
    0041138E  mov         dword ptr [x],0 
    00411395  mov         dword ptr [x],3 
    0041139C  xor         eax,eax 
    

    where the variable x is created and assigned twice (see mov dword ptr [x],0 and mov dword ptr [x],3 ).

    If observable output is modified by the variable, i.e.:

    int main()
    {
       int x = 0;
       x = 3;
       cout << x;
       return 0;
    }
    

    the generated binary will look like this:

    00401000  mov         ecx,dword ptr [__imp_std::cout (40203Ch)] 
    00401006  push        3    
    00401008  call        dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> 
    0040100E  xor         eax,eax 
    

    see that even with this, x isn’t actually generated, but rather the 3 value is put on the stack and printed directly.

    But the observed behavior in this case is the same, since 3 is printed. To the user, whether the value of x, which should be 3, is printed, or 3 is printed directly, is irrelevant.

    The bottom line is: if the behavior of the program is not changed by some statements, they are excluded. In your case, the variable x is not even created.

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

Sidebar

Related Questions

Im using c# .net windows form application. i have a SQL database with 5
Im using c# .net windows form application. I have many databases created using sql
Im using c# .net windows form application. I have loaded names of all the
All I have built a windows form application using VS 2005 Standard edition which
I have a Windows Form application built on a data model and a Windows
I have a simple Windows Forms (C#, .NET 2.0) application, built with Visual Studio
I have created a Windows Form Application using Visual C# 2008 Express Edition with
I have built a touch screen application using Windows Forms. It works great but
I have a simple winforms application in VB.NET 2008. I am using a form
I have a windows form application that uses a Shared class to house all

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.