Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

bool default initialize

Posted on 1998-07-01
3
Medium Priority
?
1,886 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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 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 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.
Suggested Courses

718 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