Operators

Meaning

+

Addition

–

Subtraction

*

Multiplication

/

Division

%

Remainder

% operator is also referred as modulus operator. It generates remainder after the integer division. The second data supplied for the / and % operator should be non zero. Operators separate identifiers in a statement/expression.
a + b = a a and b operands + operator
Operators act upon data items (variable, constants). The data items upon which operation is performed are called operands. Some operators required a single operand, while others may required two or even three operands. Operators which take only one operand are called unary (nomadic) operators and operators which take tow operands are called binary (dyadic) operators. Examples of operations are
 a + b + takes two operands ‘a” and ‘b’. So it is binary operator
 b i takes one operand. So it is unary operator
Arithmetic Operators
Operators

Meaning

Example

+

Addition

X+y

–

Subtraction

xy

*

Multiplication

X*y

/

Division

x/y

%

Remainder

X%y (returns reminder)

Assignment Operators
variable = expression;
Operators

Example

+=

x+=y, x=x+y, x+y is equal to x=x+y;

=

x=y

*=

X*=y

/=

x/=y

%=

X%=y

In a C assignment statement, the right side can be any expression, and the left side must be variable name.
Unary Operators
Operators

Symbol

Action

Example

Increment

++

Increment the operand by one

++x, x++

Decrement

—

Decrements the operand by one

–x, x–

The statements
++x;
y;
are the equivalent of these statements:
x=x+1;
y=y1;
They differ in terms of when the increment or decrements is performed;
 When used in prefix mode, the increment and decrements operators modify their operand before it’s used.
 When used in postfix mode, the increment and decrements operators modify their operand after it’s used.
an example of prefix mode
x=10;
y=x++;
after these statements are executed, x has the value 11, and y has the value 10. The value of x was assigned to y, and then x was incremented. In contrast, the following statements result in both y and x having the value 11. x is incremented, and then its value is assigned to y. an example of postfix mode;
x=10;
y= ++x;
Relational Operators
Relational operators are used to compare expression , asking questions such as “is x greater than 50?” or “is y is equal to 0?” an expression containing a relational operator evaluates to either true (1) or false (0).
Operators

Symbol

Example

Equal

==

x ==y

Greater than

>

x>y

Less than

<

x<y

Greater than or equal to

>=

x>=y

Less than or equal to

<=

x<=y

Not equal

!=

x!=y

Logical Operators
Operators

Symbol

Example

AND

&&

Expression1 && Expression2

OR



Expression1  Expression2

NOT

!

!expression1

Ternary Operator
expression1? expression2 : expression3;
if expression1 evaluates to true (that is, nonzero), the entire expression evaluates to the value of expression2. If expression evaluates to false (tat is zero), the entire expression evaluates as the value of expression3. For example, the following statement assigns the value 1 to x if y is true
and assigns 100 to x if y is false.
x=y?1:100;
Likewise, to make z equal to the larger of x and y, you could write
z=(x>y)?x:y;
perhaps you have noticed that the conditional operator functions somewhat like an if statement. The preceding statement could also be written like this.
if(x>y)
z=x;
else
z=y;
The ternary operator can’t be used in all situations in place of an if…else construction, but the conditional operators is more concise. The ternary operator can also be used in places you can’t use an if statement,such as inside a single printf() statement.
printf("The larger value is %d",((x>y)?x:y));
Comma Operator
{
int a,b,c;
c=(a=10, b=20, a+b);
printf("C=%d",c);
}
Sizeof Operator
sizeof(object);
printf("size of char = %u bytes", sizeof(char));
printf("size of int = %u bytes",sizeof(int));
printf("size of float = %u bytes",sizeof(float));
printf("size of double = %u bytes",sizeof(double));
printf("size of char = %u bytes",sizeof(a));
printf("size of int = %u bytes",sizeof(5));
Conditional Operator
The conditional operator in C is also known as ternary operator ?:. It is called ternary operator because it takes three arguments. The conditional operator has the following construct.
expr1 ? expr2 : expr3
The expression expr1 is normally a truefalse expression. The first expression expr1 is evaluated first if it is nonzero (true) then expr2 is evaluated which is the value of the whole conditional expression. If expr1 is zero (false) then expr3 is evaluated which is the value of the whole conditional expression. Thus, a conditional expression can be used to do the work of the ifelse statement. For example the following assignment statement.
small = x<y ? x : y;
small is assigned the value of x if x is smaller than y otherwise y is assigned to small. This expression is equivalent to the following ifelse statement.
if(x<y)
small = x;
else
small = y;
C Code
#include<stdio.h>
#include<conio.h>
void main()
{
int a = 5, b = 8;
int c;
c = (a < b)? a : b;
printf(ā%dā, c);
}