Operators in C
Operators in C
Arithmetic Operators:
* These operators are used to perform Arithmetic operations such as
addition,subtraction,etc.
Operator Meaning Expression
+ Addition a+b
- Subtraction a-b
* Multiplication a*b
/ Division a/b (Quotient)
% Modulus Divsion a%b (Reminder)
Relational Operators:
* These operators are also called comparision Operators
* Used to compare two values and result will be either true or false.
Logical Operators:
* These operators are used to combine two expressions.
1.Logical AND(&&)
2.Logical OR (||)
3.Logical NOT(!)
1.Logical AND(&&):
* Return true when two expressions are true.
* Return false when one of the expression is false.
Truth Table:
Exp1 Exp2 Exp1 && Exp2
True True True
True False False
False True False
False False False
2.Logical OR(||):
* Return false when two expressions are false.
* Return true when one of the expression is true.
Truth Table:
Exp1 Exp2 Exp1 || Exp2
True True True
True False True
False True True
False False False
Conditional Operator:
* The purpose of conditional operator is to test a condition and select
either true or false statement.
* This operator is denoted by using ?:
* ? is used to test a condition.
* : is used to saperate true and false statements.
syntax:
(condition)?true-statement:false-statement;
case 1:
a=10,b=20
10>20 => false => B is big
case 2:
a=12, b=5
12>5 => true => A is big
Assignment Operator:
* This operator is used to assign a value to a variable.
* This operator is denoted by using =
* you can store value directly into a vairable.
syntax:
variablename=value;
ex:
int x=20;