Solved

bool default initialize

Posted on 1998-07-01
3
1,882 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

730 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