Question:

How Do you declare a Boolean Array that has all values true?

by  |  earlier

0 LIKES UnLike

I'm taking a course on C++ Programming and I can't figure out how to set all the values of an Array(with 300 values) to true without just using a big time- consuming while loop that individually sets them all to true.

Is there any specific function or statement that sets all the values to true?

 Tags:

   Report

2 ANSWERS




  1. int SIZE = 300 ;

    bool a[SIZE] = { true };

    This should work as long as ur C++ compiler defines a bool  data type ; btw, the while loop solution works as well ....


  2. Sorry, but dfdf is incorrect.  

    You can't put bool a[SIZE];

    You can, however use bool a[300]; which is what I'm guessing you're doing.

    If you init one member of the array, all the rest will be init to 0.  So you could easily initialize all the members to false, but not to true. (This is my version of C++ anyway; if yours has true=0 you'd be fine.)

    So if you really want all members of the array to be true, you'd have:

    int SIZE = 300;     // ala dfdf

    bool* a;

    a = new bool[SIZE];

    for (int i = 0; i < SIZE; i++)

       a[i] = true;

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions