C++ Logical Operations Questions

Asked 2 years ago, Updated 2 years ago, 60 views

#include <iostream>

using namespace std;

int main()
{
    char id[6] = "apple";
    if (id == "apple")
    {
        cout << "True";
    }
    else
    {
        cout << "False";
    }
    return 0;
}

== among operators is an operator that compares whether the values are the same or different among logical operators, right? Then shouldn't the value "apple" be displayed as True in the if statement when the value is entered in the variable id as above? It's my first time doing c++, so I'm not sure Haha

c++ operator logical-operations

2022-09-20 21:48

1 Answers

char id[6] = "apple"; When you execute a command statement, id[0] == "a" id[1] == "p" id[2] == "p" id[3] == "l" id[4] == "e" The "apple" is going to be scattered a, p, p, l, e.

In the conditional statement if(id == "apple"), id is not the entire array id Accepts a specific column of array id (id[random]).


2022-09-20 21:48

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.