Arithmetic, logical and relational operators

Arithmetic operators
OperatorDetils
+Addition of two operands
-Subtraction of two operands
*Multiplication of two operands
/Division of two operands
%Reminder of a division
++Increment by one
--Decrement by one
Examples of Arithmetic Operators.
#include <stdio.h>
int main()
{
int x=30 ,y=20;
int result;

result = x + y; // Addition 
printf(" Output : %d \n", result);

result = x - y; // Subtraction  
printf(" Output : %d \n", result);

result = x * y; // Multiplication  
printf(" Output : %d \n", result);

result = x / y; // Division
printf(" Output : %d \n", result);

result = x % y; // reminder of the Division
printf(" Output : %d \n", result);
}
output
 Output : 50
 Output : 10
 Output : 600
 Output : 1
 Output : 10
Logical operators
OperatorDetils
&&And operator. Output true only if all operands are true
||Or operator. Output true if any one of the operand is true
!Not operator. True if out put of condition is false
Examples ( Output is after comment )
#include <stdio.h>
int main()
{
int x=40 ,y=50;
int result;

result= (x==40) && (y ==30);
printf(" Output : %d \n", result );  //  0

result= (x==40) || (y ==30);
printf(" Output : %d \n", result );  //  1

result= !(x==40) || (y ==30);
printf(" Output : %d \n", result );  // 0
}

Relational operators

Here output is always True or False. It can be 1 or 0
OperatorDetils
==Equal To
<Less than
>Greater than
<=Less than or equal to
>=Greater than or equal to
!=Not equal to
Test on Operators Example of Relational Operators ( output are shown with comments )
#include <stdio.h>
int main()
{
int x=30 ,y=20;

printf(" Output : %d \n", x == y);  // 0
printf(" Output : %d \n", x <  y);  // 0
printf(" Output : %d \n", x >  y);  // 1
printf(" Output : %d \n", x <= y);  // 0
printf(" Output : %d \n", x >= y);  // 1
printf(" Output : %d \n", x != y);  // 1
}


plus2net.com



Post your comments , suggestion , error , requirements etc here




We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2020 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer