Thread: C++ handles uninitialized variables

  1. #1
    Registered User
    Join Date
    Sep 2009
    Posts
    41

    Question C++ handles uninitialized variables

    Can you help me, explain question this, i dont understand it

    How does C++ handles uninitialized variables?


    thanks.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    It doesn't (unless the variable is a non-POD, in which case the defaut constructor is invoked).

  3. #3
    ...and never returned. StainedBlue's Avatar
    Join Date
    Aug 2009
    Posts
    168
    Space large enough for the particular data-type is allocated on the stack, but consequently the value of that stack space is left unchanged. It is not zero or some common arbitrary value, it is whatever was there to begin with.

    Try the following and see what you get:
    Code:
    #include <iostream>
    
    int main()
    {
      int num;
      std::cout << num << "\n";
      return 0;
    }
    Your output will be some seemingly random numbers, and it will differ from what I get, or anyone else gets.

  4. #4
    Registered User
    Join Date
    Sep 2009
    Posts
    20
    thanks you, but can you detail it more

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by akaile View Post
    thanks you, but can you detail it more
    How could one possibly elaborate on the statement "it doesn't"?

    Nothing happens. No code is executed. Not a single bit is disturbed.

    Clear enough now?

  6. #6
    Registered User
    Join Date
    Sep 2009
    Posts
    41
    thanks all

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Protected / Private Variables accessable.
    By +Azazel+ in forum C++ Programming
    Replies: 19
    Last Post: 09-08-2009, 07:39 PM
  2. basic question about global variables
    By radeberger in forum C++ Programming
    Replies: 0
    Last Post: 04-06-2009, 12:54 AM
  3. Remotely Creating Variables
    By Rajin in forum C++ Programming
    Replies: 1
    Last Post: 04-26-2005, 11:20 PM
  4. Declaring an variable number of variables
    By Decrypt in forum C++ Programming
    Replies: 8
    Last Post: 02-27-2005, 04:46 PM
  5. functions to return 2 variables?
    By tim in forum C Programming
    Replies: 5
    Last Post: 02-18-2002, 02:39 PM