Working with Operators

 Logical Operator:

 There are three basic operators namely OR,  AND, NOT which are identified as || , && , ! in C language. Also, we have came across it many a times in our programs up till now.

Unary operator:

The unary operator tells the compiler to reverse the sign by subtracting the value from zero. The effect it has is similar to using the -ve sign to indicate a number less than zero. 

 Example: Which of the following is valid?

1. valuea= -12 //valuea is int

2. valuea = - valueb -12 //valuea and valueb bith are int

Solution: both are valid

Binary operator:

Binary operator in c is the same as in other programming languages. These are + , - , *, /, % operator. The ( ) are used to clarify complex operations.

We have used these operators quite a lot in the programs.

Ternary Operator:

We studied about the if...else constructs in the previous posts isn't it the ternary operators are just the short hand of if ...else. These are represented by ? : 

Syntax: (test expression)?(True-expression):(False-Expression) 

Compound Assignment Operator:

Apart from the standard assignment operator =, C offers this feature as well let us see in an example.

Example:

total= total+sum;

this statement can be also be written as 

total+=sum;

above assignment operator can also be applied in - ,  / , * ,  %.

Increment and Decrement operator:

we have used these a lot in our programs isn't it these are just responsible for incrementing a value and decrementing a value I have already discussed about these in the getting started section as well.

these are pre and post based upon their application .

a++; post increment

++a; pre increment

--a; pre decrement

a--; post decrement



 

 

Comments