Solved

bool default initialize

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now