Professional Documents
Culture Documents
ARITHMETIC OPERATORS
PREFIX/POSTFIX OPERATORS
ASSIGNMENT OPERATORS
RELATIONAL OPERATORS
LOGICAL AND BOOLEAN OPERATORS
TERNARY OPERATORS
ARITHMETIC OPERATORS
() BRACKETS
* MULTIPLICATION
/ DIVISION
+ ADDITION
- SUBTRACTION
% MODULUS
= ASSIGNMENT
#include <stdio.h>
int main(){
int x=10, y=20;
int result;
int remainder;
printf(“x=%d\n”,x);
printf(“y=%d\n”,y);
result=x+y;
printf(“The sum of x+y is %d\n”,result);
result = x*2;
printf(“The product of x*2 is %d\n”,result);
result = y-10;
printf(“the difference of y-10 is %d\n”, result);
result=y/x;
printf(“the quotient of y/x is %d\n”,result);
remainder = x%4;
printf(“the remainder of x%4 is %d\n”, remainder);
return 0;}
int main() {
int a=5,b;
b= ++a + 5;
printf("a=%d b=%d",a,b);
return 0;
}
int main() {
int a=5,b;
b= a++ + 5;
printf("a=%d b=%d",a,b);
return 0;
}
ASSIGNMENT OPERATORS
*= MULTIPLICATION ASSIGNMENT
/= DIVISION ASSIGNMENT
%= MODULUS ASSIGNMENT
+= ADDITION ASSIGNMENT
-= SUBTRACTION ASSIGNMENT
EXAMPLE:
Y=10;
Y+=10, Y=20
Y-=5, Y=15
Y*=4, Y=60
Y/=2, Y=30
int main() {
int x=10;
int y=x;
printf(“y=%d”,y);
y+=10;
printf(“y+=10; y%d”, y);
y-=5;
printf(“y-=5; y=%d”,y);
y*=4;
printf(“y*=4; y=%d”, y);
y/=2;
printf(“y/=2; y=%d,” y);
return 0; }
RELATIONAL OPERATORS
Int main(){
Int x=10, y=20;
printf(“x=%d, x);
printf(“y=%d, y);
if (x==y) printf(“true”);
else printf(“false”);
if(x!=y) printf(“true”);
else printf(“false”);
if(x>y) printf(“true”);
else(“false”);
if(x<y) printf(“true”);
else printf(“false”);
return0; }
LOGICAL/BOOLEAN OPERATOR
&& AND A<B && C<D TRUE, WHEN A<B AND C<D
|| OR A>B || C>D TRUE, WHEN A>B OR C>D
! NOT !A NOT A
Int main(){
Int x=7, y=10;
x++;
if(x<y||y<20) printf(“true”);
else printf(“false”);
y++;
if(x>y&&y>0) printf(“true”);
else printf(“false”);
return 0;}
TERNARY OPERATOR
If(expression1)
Return expression2;
Else return expression3;
RADIX CHANGING
%o OCTAL
%x HEX
Activity:
Create a program that prints the sum, difference, product and quotient of the two given numbers A=7, and x=9.