Search code examples
cboolean-logicboolean-operations

Logical AND operator


I am little confused with logical AND operator. I have these 2 lines of code. Here num and j are both int. I have a situation where both the conditions are satisfied, but I don't know why it's not printing the value of j. Can anybody point out the mistakes? Thanks in advance.

if(k==1 && num%j==0)
    printf("%d",j);

Solution

  • In plain English, the expression k == 1 && num % j == 0 is true if and only if k equals 1 and the remainder from dividing num by j is 0. Not much more I can say.