Please Help! Thanks! Using Relational and Logical Operators to Evaluate Logical
ID: 3697298 • Letter: P
Question
Please Help! Thanks!
Using Relational and Logical Operators to Evaluate Logical (Boolean) Expressions
Evaluate the logical (Boolean) expression in the Expression column, and state all possible answers in the Result column. For char and string types, use the ASCII collating sequence.
1.
string name1 = “Aaron”;
string name2 = “aaron”;
(name1 == name2)
2.
string name1 = “Aaron”;
string name2 = “Aardvark”;
(name1 <= name2)
3.
bool flag = true;
int a = 2, b = 5, c = 10;
(a * b <= c && ! flag)
4.
char letter = ‘A’;
string word = “A”;
(letter == word)
1.
string name1 = “Aaron”;
string name2 = “aaron”;
(name1 == name2)
2.
string name1 = “Aaron”;
string name2 = “Aardvark”;
(name1 <= name2)
3.
bool flag = true;
int a = 2, b = 5, c = 10;
(a * b <= c && ! flag)
4.
char letter = ‘A’;
string word = “A”;
(letter == word)
Explanation / Answer
1.
string name1 = “Aaron”;
string name2 = “aaron”;
(name1 == name2) evaluates to False. As the capital alphabet is not equal to small alphabet.
2.
string name1 = “Aaron”;
string name2 = “Aardvark”;
(name1 <= name2) evaluates to False.
3.
bool flag = true;
int a = 2, b = 5, c = 10;
(a * b <= c && ! flag) . a*b is 2 * 5 = 10 <= 10 is true. Now true && false evaluates to False.
4.
char letter = ‘A’;
string word = “A”;
(letter == word) will lead to a syntax error, as a string and character are not comparable.