Do booleans start off true or false?

Or do I have to set what they start off as?

If i DO then how do I set all values of a 2 dimensional boolean array to true.
Last edited on
No primitive type has any "starting" value. It's garbage data left over from whatever occupied its memory previously. If you have a lucky compiler extension it might initialize them for you but that's not usually the case. And it's also nonstandard.
Long and short: all primitive types must be initialized or given a value EXPLICITLY by the user prior to use, and all other behavior is undefined.
Ok thanks so how would I set bool seats[15][30] to all true?

do i have to go 1 by 1
You really want to know what I'd do?
Alright. I'd define a wrapper class with a default constructor that sets them to true. I'd overload =, ==, !=, >> and << for the purpose of operating on this wrapper class. That saves me the time of having to initialize them all myself. Chances are this is not reasonable for one project though.
So what would you do? Try a nested for loop, going through each row and each column. Cycle through the booleans and set them all to true. There's not much else I can think of.
Last edited on
Almost. But it's not quite the same.
I suppose you could also do something like: memset(seats,1,15*30);

For more info about memset check this out: http://www.cplusplus.com/reference/clibrary/cstring/memset/
Last edited on
prefer std::fill (or std::fill_n) to memset

http://cplusplus.com/reference/algorithm/fill_n/

I especially wouldn't use memset on bools. On an array of bools no less!

 
std::fill_n(&seats[0][0], 15*30, true);
Topic archived. No new replies allowed.