Fop Operater
Fop Operater
2.1 Operators
I. Arithmetic Operators
An arithmetic operator performs mathematical operations such as addition,
subtraction and multiplication on numerical values (constants and variables).
Operator Meaning
* multiplication
/ division
Example:
void main()
{
int a = 9,b = 4, c;
c = a+b;
printf("a+b = %d \n",c);
c = a-b;
printf("a-b = %d \n",c);
c = a*b;
printf("a*b = %d \n",c);
c=a/b;
printf("a/b = %d \n",c);
c=a%b;
printf("Remainder when a divided by b = %d \n",c);
}
Output:
a+b = 13
a-b = 5
a*b = 36
a/b = 2
Remainder when a divided by b=1
1
FOP
Operator Meaning
+ unary plus
++ Increment
-- Decrement
& Address of
! Logical negation
2
FOP
== Equal to 5 == 3 returns 0
3
FOP
}
Output:
5 == 5 = 1
5 == 10 = 0
5 >5=0
5 > 10 = 0
5 <5=0
5 < 10 = 1
5 != 5 = 0
5 != 10 = 1
5 >= 5 = 1
5 >= 10 = 0
5 <= 5 = 1
5 <= 10 = 1
4
FOP
V. Assignment Operator
An assignment operator is used for assigning a value to a variable. The most
common assignment operator is =
Operator Meaning Example
= a=b a=b
+= a += b a = a+b
-= a -= b a = a-b
*= a *= b a = a*b
/= a /= b a = a/b
%= a %= b a = a%b
5
FOP
Example:
#include <stdio.h>
void main()
{
int a , b;
a = 10;
printf( "Value of b is %d\n", (a == 1) ? 20: 30 );
Here, operators with the highest precedence appear at the top of the table, those
with the lowest appear at the bottom. Within an expression, higher precedence
operators will be evaluated first
6
FOP
7
FOP
2.2 Expressions
Expressions are combination of variables, constant and operators.
Expressions are evaluated using an assignment statement of the form:
In the above syntax, variable is any valid C variable name. When the statement like
the above form is encountered, the expression is evaluated first and then the value
is assigned to the variable on the left hand side. All variables used in the expression
must be declared and assigned values before evaluation is attempted. Examples of
expressions are:
Eg.
A+B, c=d-e, a++, --d, a<b, b>a && c<d
I. Arithmetic Expressions
Arithmetic Expressions are combination of Constant, variable and Arithmetic
operators.
Example.
A+B, C-D, X/Y etc…
void main()
{
int a = 9,b = 4, c;
c = a+b;
printf("a+b = %d \n",c);
c = a-b;
printf("a-b = %d \n",c);
c = a*b;
printf("a*b = %d \n",c);
c=a/b;
printf("a/b = %d \n",c);
c=a%b;
8
FOP
}
Output:
a+b = 13
a-b = 5
a*b = 36
a/b = 2
Remainder when a divided by b=1
9
FOP
10
FOP
Example:
1. a=10, b=12
C=a+b
=22
2. a=10, b=20,c=40
d=a+b*c
10+20*40
10+800
810
3. a=10,b=20,c=30,d=40
z=(a+b)-(c+d)
(30)-(70)
-40
11