C++ if statement explanation confusion [closed]












-3















I am new to C++ and sometimes it is difficult for me to understand complex if statements, could anyone help explain following code to me? Thanks in advance.
Given:



int vis[25], g[25][25], Ty[25][25];

for (int i = 1; i < 30; i++)
{
if(!vis[i] && g[x][i] == 1 && Ty[f][i] != n) {...}
}


Vis is an array and only initialized and there is no any assigned value in it at the moment.
So what does !vis[i] mean?
Does it mean vis[i] !=0 or vis[i]==1 or something else ?










share|improve this question













closed as unclear what you're asking by Neil Butterworth, Matthieu Brucher, Sid S, Killzone Kid, ead Nov 26 '18 at 9:26


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • 6





    What does your C++ textbook have to say on the subject?

    – Neil Butterworth
    Nov 24 '18 at 23:48






  • 4





    This is fundamental language construct that any decent textbook will cover. Please grab a good textbook and work through the fundamentals of the language. That will more helpful to you in the long run than getting an answer to this specific question.

    – R Sahu
    Nov 24 '18 at 23:51











  • int vis[25] then for (int i = 1; i < 30; i++) then vis[i] is a bug. i must be between 0 and 24 for an array of 25 elements.

    – drescherjm
    Nov 24 '18 at 23:55


















-3















I am new to C++ and sometimes it is difficult for me to understand complex if statements, could anyone help explain following code to me? Thanks in advance.
Given:



int vis[25], g[25][25], Ty[25][25];

for (int i = 1; i < 30; i++)
{
if(!vis[i] && g[x][i] == 1 && Ty[f][i] != n) {...}
}


Vis is an array and only initialized and there is no any assigned value in it at the moment.
So what does !vis[i] mean?
Does it mean vis[i] !=0 or vis[i]==1 or something else ?










share|improve this question













closed as unclear what you're asking by Neil Butterworth, Matthieu Brucher, Sid S, Killzone Kid, ead Nov 26 '18 at 9:26


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • 6





    What does your C++ textbook have to say on the subject?

    – Neil Butterworth
    Nov 24 '18 at 23:48






  • 4





    This is fundamental language construct that any decent textbook will cover. Please grab a good textbook and work through the fundamentals of the language. That will more helpful to you in the long run than getting an answer to this specific question.

    – R Sahu
    Nov 24 '18 at 23:51











  • int vis[25] then for (int i = 1; i < 30; i++) then vis[i] is a bug. i must be between 0 and 24 for an array of 25 elements.

    – drescherjm
    Nov 24 '18 at 23:55
















-3












-3








-3








I am new to C++ and sometimes it is difficult for me to understand complex if statements, could anyone help explain following code to me? Thanks in advance.
Given:



int vis[25], g[25][25], Ty[25][25];

for (int i = 1; i < 30; i++)
{
if(!vis[i] && g[x][i] == 1 && Ty[f][i] != n) {...}
}


Vis is an array and only initialized and there is no any assigned value in it at the moment.
So what does !vis[i] mean?
Does it mean vis[i] !=0 or vis[i]==1 or something else ?










share|improve this question














I am new to C++ and sometimes it is difficult for me to understand complex if statements, could anyone help explain following code to me? Thanks in advance.
Given:



int vis[25], g[25][25], Ty[25][25];

for (int i = 1; i < 30; i++)
{
if(!vis[i] && g[x][i] == 1 && Ty[f][i] != n) {...}
}


Vis is an array and only initialized and there is no any assigned value in it at the moment.
So what does !vis[i] mean?
Does it mean vis[i] !=0 or vis[i]==1 or something else ?







c++ if-statement operator-keyword boolean-operations






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 24 '18 at 23:44









WeiWei

1




1




closed as unclear what you're asking by Neil Butterworth, Matthieu Brucher, Sid S, Killzone Kid, ead Nov 26 '18 at 9:26


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









closed as unclear what you're asking by Neil Butterworth, Matthieu Brucher, Sid S, Killzone Kid, ead Nov 26 '18 at 9:26


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 6





    What does your C++ textbook have to say on the subject?

    – Neil Butterworth
    Nov 24 '18 at 23:48






  • 4





    This is fundamental language construct that any decent textbook will cover. Please grab a good textbook and work through the fundamentals of the language. That will more helpful to you in the long run than getting an answer to this specific question.

    – R Sahu
    Nov 24 '18 at 23:51











  • int vis[25] then for (int i = 1; i < 30; i++) then vis[i] is a bug. i must be between 0 and 24 for an array of 25 elements.

    – drescherjm
    Nov 24 '18 at 23:55
















  • 6





    What does your C++ textbook have to say on the subject?

    – Neil Butterworth
    Nov 24 '18 at 23:48






  • 4





    This is fundamental language construct that any decent textbook will cover. Please grab a good textbook and work through the fundamentals of the language. That will more helpful to you in the long run than getting an answer to this specific question.

    – R Sahu
    Nov 24 '18 at 23:51











  • int vis[25] then for (int i = 1; i < 30; i++) then vis[i] is a bug. i must be between 0 and 24 for an array of 25 elements.

    – drescherjm
    Nov 24 '18 at 23:55










6




6





What does your C++ textbook have to say on the subject?

– Neil Butterworth
Nov 24 '18 at 23:48





What does your C++ textbook have to say on the subject?

– Neil Butterworth
Nov 24 '18 at 23:48




4




4





This is fundamental language construct that any decent textbook will cover. Please grab a good textbook and work through the fundamentals of the language. That will more helpful to you in the long run than getting an answer to this specific question.

– R Sahu
Nov 24 '18 at 23:51





This is fundamental language construct that any decent textbook will cover. Please grab a good textbook and work through the fundamentals of the language. That will more helpful to you in the long run than getting an answer to this specific question.

– R Sahu
Nov 24 '18 at 23:51













int vis[25] then for (int i = 1; i < 30; i++) then vis[i] is a bug. i must be between 0 and 24 for an array of 25 elements.

– drescherjm
Nov 24 '18 at 23:55







int vis[25] then for (int i = 1; i < 30; i++) then vis[i] is a bug. i must be between 0 and 24 for an array of 25 elements.

– drescherjm
Nov 24 '18 at 23:55














2 Answers
2






active

oldest

votes


















1














int vis[25], g[25][25], Ty[25][25];


Declares 3 arrays. "vis" is 1D array of size 25, "g" is 2D array of size 25x25, and same with "Ty".



    if(!vis[i] && g[x][i] == 1 && Ty[f][i] != n) {...}


In C++, integers evaluate to "false" in boolean expressions if the value is 0, and "true" for all other values. So in the if statement, the first expression "!vis[i]" will evaluate to true when vis[i] == 0.



The second expression will evaluate true when the value at index [x][i] in 'g' is equal to 1.



The third statement will evaluate to true when the value at index [f][i] in 'Ty' is not equal to some variable 'n', which is presumably defined somewhere in your program like 'x'.



*Note - as drescherjm noted in a comment, the for-loop should only go up to 24, as the size of your arrays is 25 in either direction, so accessing an element outside the range 0-24 (inclusive) is undefined behavior.






share|improve this answer

































    0















    • A int is only false if it's 0. This means with any other number the string is true.

    • A ! in front of a logical statement negates it.


    So the if check:





    1. the array vis on position i has to be 0.



      !vis[i] == !(vis[i] != 0) == vis[i] == 0



    2. The array value of g on x, i must be one


    3. The array of Ty on position f, i cannot be equal to the value in n






    share|improve this answer





















    • 1





      Actually 1 means - vis[i] == 0 and it cannot be null as vis[i] is not a pointer

      – Slava
      Nov 24 '18 at 23:56













    • @Slava Oh, right. It is not null but it is 0. I'll correct it.

      – Darkproduct
      Nov 24 '18 at 23:57











    • 1 says vis[i] must be equal 0, not the other way around

      – Slava
      Nov 24 '18 at 23:59











    • @Slava absolutely right... I don't know what I've thought...

      – Darkproduct
      Nov 25 '18 at 0:02


















    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    int vis[25], g[25][25], Ty[25][25];


    Declares 3 arrays. "vis" is 1D array of size 25, "g" is 2D array of size 25x25, and same with "Ty".



        if(!vis[i] && g[x][i] == 1 && Ty[f][i] != n) {...}


    In C++, integers evaluate to "false" in boolean expressions if the value is 0, and "true" for all other values. So in the if statement, the first expression "!vis[i]" will evaluate to true when vis[i] == 0.



    The second expression will evaluate true when the value at index [x][i] in 'g' is equal to 1.



    The third statement will evaluate to true when the value at index [f][i] in 'Ty' is not equal to some variable 'n', which is presumably defined somewhere in your program like 'x'.



    *Note - as drescherjm noted in a comment, the for-loop should only go up to 24, as the size of your arrays is 25 in either direction, so accessing an element outside the range 0-24 (inclusive) is undefined behavior.






    share|improve this answer






























      1














      int vis[25], g[25][25], Ty[25][25];


      Declares 3 arrays. "vis" is 1D array of size 25, "g" is 2D array of size 25x25, and same with "Ty".



          if(!vis[i] && g[x][i] == 1 && Ty[f][i] != n) {...}


      In C++, integers evaluate to "false" in boolean expressions if the value is 0, and "true" for all other values. So in the if statement, the first expression "!vis[i]" will evaluate to true when vis[i] == 0.



      The second expression will evaluate true when the value at index [x][i] in 'g' is equal to 1.



      The third statement will evaluate to true when the value at index [f][i] in 'Ty' is not equal to some variable 'n', which is presumably defined somewhere in your program like 'x'.



      *Note - as drescherjm noted in a comment, the for-loop should only go up to 24, as the size of your arrays is 25 in either direction, so accessing an element outside the range 0-24 (inclusive) is undefined behavior.






      share|improve this answer




























        1












        1








        1







        int vis[25], g[25][25], Ty[25][25];


        Declares 3 arrays. "vis" is 1D array of size 25, "g" is 2D array of size 25x25, and same with "Ty".



            if(!vis[i] && g[x][i] == 1 && Ty[f][i] != n) {...}


        In C++, integers evaluate to "false" in boolean expressions if the value is 0, and "true" for all other values. So in the if statement, the first expression "!vis[i]" will evaluate to true when vis[i] == 0.



        The second expression will evaluate true when the value at index [x][i] in 'g' is equal to 1.



        The third statement will evaluate to true when the value at index [f][i] in 'Ty' is not equal to some variable 'n', which is presumably defined somewhere in your program like 'x'.



        *Note - as drescherjm noted in a comment, the for-loop should only go up to 24, as the size of your arrays is 25 in either direction, so accessing an element outside the range 0-24 (inclusive) is undefined behavior.






        share|improve this answer















        int vis[25], g[25][25], Ty[25][25];


        Declares 3 arrays. "vis" is 1D array of size 25, "g" is 2D array of size 25x25, and same with "Ty".



            if(!vis[i] && g[x][i] == 1 && Ty[f][i] != n) {...}


        In C++, integers evaluate to "false" in boolean expressions if the value is 0, and "true" for all other values. So in the if statement, the first expression "!vis[i]" will evaluate to true when vis[i] == 0.



        The second expression will evaluate true when the value at index [x][i] in 'g' is equal to 1.



        The third statement will evaluate to true when the value at index [f][i] in 'Ty' is not equal to some variable 'n', which is presumably defined somewhere in your program like 'x'.



        *Note - as drescherjm noted in a comment, the for-loop should only go up to 24, as the size of your arrays is 25 in either direction, so accessing an element outside the range 0-24 (inclusive) is undefined behavior.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 25 '18 at 20:56

























        answered Nov 25 '18 at 0:00









        user3150552user3150552

        5217




        5217

























            0















            • A int is only false if it's 0. This means with any other number the string is true.

            • A ! in front of a logical statement negates it.


            So the if check:





            1. the array vis on position i has to be 0.



              !vis[i] == !(vis[i] != 0) == vis[i] == 0



            2. The array value of g on x, i must be one


            3. The array of Ty on position f, i cannot be equal to the value in n






            share|improve this answer





















            • 1





              Actually 1 means - vis[i] == 0 and it cannot be null as vis[i] is not a pointer

              – Slava
              Nov 24 '18 at 23:56













            • @Slava Oh, right. It is not null but it is 0. I'll correct it.

              – Darkproduct
              Nov 24 '18 at 23:57











            • 1 says vis[i] must be equal 0, not the other way around

              – Slava
              Nov 24 '18 at 23:59











            • @Slava absolutely right... I don't know what I've thought...

              – Darkproduct
              Nov 25 '18 at 0:02
















            0















            • A int is only false if it's 0. This means with any other number the string is true.

            • A ! in front of a logical statement negates it.


            So the if check:





            1. the array vis on position i has to be 0.



              !vis[i] == !(vis[i] != 0) == vis[i] == 0



            2. The array value of g on x, i must be one


            3. The array of Ty on position f, i cannot be equal to the value in n






            share|improve this answer





















            • 1





              Actually 1 means - vis[i] == 0 and it cannot be null as vis[i] is not a pointer

              – Slava
              Nov 24 '18 at 23:56













            • @Slava Oh, right. It is not null but it is 0. I'll correct it.

              – Darkproduct
              Nov 24 '18 at 23:57











            • 1 says vis[i] must be equal 0, not the other way around

              – Slava
              Nov 24 '18 at 23:59











            • @Slava absolutely right... I don't know what I've thought...

              – Darkproduct
              Nov 25 '18 at 0:02














            0












            0








            0








            • A int is only false if it's 0. This means with any other number the string is true.

            • A ! in front of a logical statement negates it.


            So the if check:





            1. the array vis on position i has to be 0.



              !vis[i] == !(vis[i] != 0) == vis[i] == 0



            2. The array value of g on x, i must be one


            3. The array of Ty on position f, i cannot be equal to the value in n






            share|improve this answer
















            • A int is only false if it's 0. This means with any other number the string is true.

            • A ! in front of a logical statement negates it.


            So the if check:





            1. the array vis on position i has to be 0.



              !vis[i] == !(vis[i] != 0) == vis[i] == 0



            2. The array value of g on x, i must be one


            3. The array of Ty on position f, i cannot be equal to the value in n







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 25 '18 at 0:02

























            answered Nov 24 '18 at 23:53









            DarkproductDarkproduct

            304116




            304116








            • 1





              Actually 1 means - vis[i] == 0 and it cannot be null as vis[i] is not a pointer

              – Slava
              Nov 24 '18 at 23:56













            • @Slava Oh, right. It is not null but it is 0. I'll correct it.

              – Darkproduct
              Nov 24 '18 at 23:57











            • 1 says vis[i] must be equal 0, not the other way around

              – Slava
              Nov 24 '18 at 23:59











            • @Slava absolutely right... I don't know what I've thought...

              – Darkproduct
              Nov 25 '18 at 0:02














            • 1





              Actually 1 means - vis[i] == 0 and it cannot be null as vis[i] is not a pointer

              – Slava
              Nov 24 '18 at 23:56













            • @Slava Oh, right. It is not null but it is 0. I'll correct it.

              – Darkproduct
              Nov 24 '18 at 23:57











            • 1 says vis[i] must be equal 0, not the other way around

              – Slava
              Nov 24 '18 at 23:59











            • @Slava absolutely right... I don't know what I've thought...

              – Darkproduct
              Nov 25 '18 at 0:02








            1




            1





            Actually 1 means - vis[i] == 0 and it cannot be null as vis[i] is not a pointer

            – Slava
            Nov 24 '18 at 23:56







            Actually 1 means - vis[i] == 0 and it cannot be null as vis[i] is not a pointer

            – Slava
            Nov 24 '18 at 23:56















            @Slava Oh, right. It is not null but it is 0. I'll correct it.

            – Darkproduct
            Nov 24 '18 at 23:57





            @Slava Oh, right. It is not null but it is 0. I'll correct it.

            – Darkproduct
            Nov 24 '18 at 23:57













            1 says vis[i] must be equal 0, not the other way around

            – Slava
            Nov 24 '18 at 23:59





            1 says vis[i] must be equal 0, not the other way around

            – Slava
            Nov 24 '18 at 23:59













            @Slava absolutely right... I don't know what I've thought...

            – Darkproduct
            Nov 25 '18 at 0:02





            @Slava absolutely right... I don't know what I've thought...

            – Darkproduct
            Nov 25 '18 at 0:02



            Popular posts from this blog

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            TypeError: fit_transform() missing 1 required positional argument: 'X'