Questions tagged [logical-and]

Logical AND Operator ("&&") is a binary operator which yields 1 if both of its operands compare unequal to 0; otherwise, it yields 0.

Logical AND Operator (&&) is a binary operator for which each of the operands shall have scalar type. The && operator shall yield 1 if both of its operands compare unequal to 0; otherwise, it yields 0. The result has type int.

The && operator guarantees left-to-right evaluation; if the second operand is evaluated, there is a sequence point between the evaluations of the first and second operands. If the first operand compares equal to 0, the second operand is not evaluated.

Reference: Chapter 6.5.13, C11

Use it if the question is related to the use of && operator, in C, C++ or similar languages.

80 questions
212
votes
6 answers

"querySelectorAll()" with multiple conditions in JavaScript

Is it possible to make a search by querySelectorAll() using multiple unrelated conditions? If yes, how? And, how to specify whether those are AND or OR criteria? For example: How to find all forms, ps and legends with a single querySelectorAll()…
Alan Coromano
  • 24,958
  • 53
  • 135
  • 205
63
votes
7 answers

How does C++ handle &&? (Short-circuit evaluation)

When encountering a (bool1 && bool2), does c++ ever attempts to check bool2 if bool1 was found false or does it ignore it the way PHP does? Sorry if it is too basic of a question, but I really could not find a mentioning of that neither in Schildt…
Aleksandrs Ulme
  • 1,262
  • 1
  • 12
  • 21
13
votes
2 answers

difference between "&&" and "and" in kotlin

What's the difference between "&&" and "and" in kotlin? in my code, when first condition is false, i've noticed that the condition after "and" is still evaluated but not evaluated in "&&" case. why is that?
AT Amrani
  • 228
  • 1
  • 8
8
votes
5 answers

Operator precedence and evaluation order

I can't understand output of this program: #include using namespace std; int main() { int x = 1 , y = 1, z = 1; cout << ( ++x || ++y && ++z ) << endl; //outputs 1; cout << x << " " << y << " " << z ; //x = 2 , y = 1 , z = 1; …
shiva
  • 2,535
  • 2
  • 18
  • 32
7
votes
2 answers

In Postgresql, after grouping, return false if any value of a column is false. If all values are true/false, then return true/false respectively

I have a table called 'apple' and I wrote the following query: select name, count(name), case when istasty is null then false else istasty end from apple group by name, istasty; This the output: I am trying to group the name and…
7
votes
6 answers

How to have both functions called with logical AND operator (&&) c++

Let's say I had two functions and a variable, int number; bool foo (void); bool footoo (void); And in each of these functions, some logic with the variable number takes place, such as: number++; return(rand()%2); And then I call them like so: if…
James Hurley
  • 833
  • 1
  • 10
  • 33
6
votes
1 answer

What is the fastest way to calculate the logical_and (&&) between elements of two __m256i variables, looking for any pair of non-zero elements

As far as I know, integers in C++ can be treated like booleans, and we can have a code like this: int a = 6, b = 10; if (a && b) do something ---> true as both a and b are non-zero Now, assume that we have: __m256i a, b; I need to apply…
4
votes
3 answers

Non-function do while loop in C

I'm new to programming and was hoping I could get some help. I'm attempting to create a 'do while' loop in C as part of my CS50 problem sets. I'm attempting to use two different conditions under 'while', but for some reason they are not being…
Disierd
  • 53
  • 4
4
votes
3 answers

Python bitand (&) vs and

Hi all I have this part of code: for line in response.body.split("\n"): if line != "": opg = int(line.split(" ")[2]) opc = int(line.split(" ")[3]) value = int(line.split(" ")[5]) if opg==160 & opc==129: …
sharkbait
  • 2,980
  • 16
  • 51
  • 89
3
votes
3 answers

Having same expression inside case in switch statement

int main(){ char c='a'; switch(c){ case 'a' && 1: printf("Hello"); case 'b' && 1: printf("hey"); break; default : printf("Goodbye"); } } When I compile this code the result was "compilation error",…
yash
  • 77
  • 3
  • 10
3
votes
3 answers

Why is the expression true after bit shifting the value and condition with && in C

Have a look at the example: unsigned char c = 64; /* 0100 0000 */ c = (c << 2 && 512); /* 512: 10 0000 0000 */ If I shift c two times to the left, I should get from 0100 0000 (64) to this 0001 0000 0000 (256). So my 8-bit char c has only zeroes.…
B0r1
  • 400
  • 3
  • 15
3
votes
4 answers

() has the highest priority, why is it short-circuited?

() has the highest priority, why is it short-circuited? int a = 1, b = 0; (--a)&&(b++); Why is (b++) still short-circuited?
3
votes
3 answers

sed apply two search conditions to a single line and then substitute

Id like to do do the following substitution sed 's/$/)/' python2.py with the condition that a line contains print( but it may not contain print(""". A line that it should not match would be print("""Some multi line text etc... While lines like…
Hans Wurst
  • 227
  • 2
  • 15
3
votes
2 answers

C How to parse int and char in char array?

I want to parse char and int in my char array and use them in the code. For example the char array is a3. I am getting a warning: "comparison between pointer and integer." How can I fix this? bool isValid(char piece[1]){ if((piece[0] != "a") ||…
LunaAquila
  • 45
  • 4
3
votes
6 answers

||, && operators in C

Why this code only work with && operator? I think it should be ||, but I'm wrong. Choice can not be equal to 2 value at the same time? I need to ask user's input until choice will be equal to 'a' OR 'd', but why I need to write && ? I don't…
Yellowfun
  • 418
  • 1
  • 9
  • 21
1
2 3 4 5 6