a simple basic question...
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: a simple basic question...

  1. #1
    Join Date
    Mar 2011
    Posts
    3

    a simple basic question...

    hello every1..
    m a newbie to programming and am seeking help for this simple question i have...

    #include<stdio.h>
    main()
    {
    int a;
    printf("%d",a);
    }

    the output for the above program gives me something as 19345234...
    the value being displayed here is the location of the memory? or simply some garbage value tat already occupies the memory block from before...?
    wat should i add to this program so that the output displayed is null...?

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Fairfax, VA
    Posts
    10,891

    Re: a simple basic question...

    You haven't assigned any value to a, so the value of a is undefined when you print it.

  3. #3
    Join Date
    Mar 2011
    Posts
    3

    Re: a simple basic question...

    yea fine... i accept tat too... but wat is the value tat is being diplayed here?

  4. #4
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Fairfax, VA
    Posts
    10,891

    Re: a simple basic question...

    It's the value of the variable a. a is located on the stack. Since you haven't assigned anything to it, whatever bits happened to be set in that location are interpreted as an int and printed.

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,228

    Re: a simple basic question...

    Quote Originally Posted by xen_ View Post
    yea fine... i accept tat too... but wat is the value tat is being diplayed here?
    You need to get the h key on your keyboard checked.

  6. #6
    Join Date
    Apr 2008
    Posts
    118

    Re: a simple basic question...

    Tat vaL is like rite woteva, ya now? its like wot was in dat like space wen u md yr like a

  7. #7
    Join Date
    Mar 2011
    Posts
    3

    Re: a simple basic question...

    hmmm... i get it nw... thxx a lot...
    wt shud i add here so as to free up the memory?
    realloc() should work?

  8. #8
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Fairfax, VA
    Posts
    10,891

    Re: a simple basic question...

    You aren't doing any manual memory management here. There's nothing to clean up.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center