Register | Sing In

New posts

Stacks in C programming Linked Lists in C programming File Input/Output in C programming Check prime numbers in C Programming C Programming Enumeration C Programming Union

Archives

2013-10 2013-09 2013-08

Logical Operators in C programming

August 13, 2013 Posted by: GPA Views: 543 2 comments

The logical operators are && (logical AND), || (logical OR) and ! (logical NOT also called logical negation). All this operators are describe below in the table.

Operators Associativity Type
++ (postfix) -- (postfix) right to left postfix
+ - ! ++ (prefix) -- (prefix) (type) right to left unary
* / % left to right multiplicative
+ - left to right additive
< <= > >= left to right relational
== != left to right equality
== != left to right equality
&& left to right logical AND
|| left to right logical OR
?: right to left conditional
= += -= *= /= %= right to left assignment
, left to right comma

Example:

 

 

  

#include <stdio.h>
#include <stdlib.h>
//main function
int main(int argc, char *argv[]){
       int a=10;
       printf("a=%d \n",a);
       if(a==10){//left to right equality
         printf("a==10 It is true\n");
  }
       if(a>10){//left to right relational
     printf("a>10 It is true\n");
}
  if(a!=10){//left to right equality
  printf("a!=10 It is true\n");
   }
  if(a==10 || a<10){//left to right logical OR
   printf("a==10 || a<10 It is true\n"); 
}
   system("PAUSE");//delay
return 0;
}

Output

Download this example

color: teal;font-size: 12.0pt; font-family: Consolas; mso-fareast-font-family: img src=

2 Comments...

1. Stavr

August 12, 2013, 2:12 pm
Avatar

Good

2. Stavr

August 12, 2013, 1:11 pm
Avatar

How sub two number?

Leave a Reply

Please, Sing In to leave a Reply for this material.



Online Chat

LiveZilla Live Help

Popular posts

Function strtok in C programming Check prime numbers in C Programming C Programming Union Linked Lists in C programming File Input/Output in C programming C Programming Enumeration

RSS-subscribe

New materials

Subscribe