Solved

bool default initialize

Posted on 1998-07-01
3
1,884 Views
Last Modified: 2008-02-01
Is standard type bool initialized to false by default?  Or is it undefined until a value {true | false} is assigned?
0
Comment
Question by:VEngineer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 2

Accepted Solution

by:
rayb earned 0 total points
ID: 1167018
The bool is like many other types, it is uninitialized on startup.  You can easily test this for yourself, simply create an array of bools, say around 100 in size, then examine the contents of the array.
0
 
LVL 2

Author Comment

by:VEngineer
ID: 1167019
There is a special case in arrays...

Arrays defined in the global scope with fundamental base types have their array elements set to zero unless there is explicit initialization.

Arrays defined in a local scope with fundamental base types have their array elements uninitialized unless there is explicit initialization.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1167020
Actually that has nothing to do with arrays. The POD (Plain Old Data, like the built in types, but also classes and structures without constructors and virtual functions and with no members with constructors and virtual functions) are always initialized to 0 when global.  This is true regardless of whether or not they are in an array.  When local or dynamically allocated they will be set to random values.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question