Showing posts with label increment. Show all posts
Showing posts with label increment. Show all posts

9.09.2011

Increment and Decrement operators

Increment operators (++)

  • Increment operators are increase the value of subsequent. value may be increase according to the programmer.
  • Increment operator are two types as follows :
    1. Post increment
    2. Pre increment
 Decrement operators ( -- )
  • decrement operators decrease the value to one, two and so on.
  • As like Increment operators, decrement operators are also two type as : 
    1. Post decrement
    2. Pre decrement
Before we more discuss about increment and decrement operator, let understand some expression; that's are using in all operators.

Now some issues of pre and post increment and decrement, we will discuss after solve following programming :

 x = 5       x = 5     x = 5  
 x = x+1      ++x       x++    
 x = 6       x = 6      x=5       

In above program u notice that value of x increase to one in all three expression but after the increasing one, the final value of x in not same, third box result is differ to another two boxes. Now you know that c operators are mostly three types, ++ and -- operators are Unary operators.

Post increment or decrement are lowest precedence so it is solve at the end of program. Hence above program in third box first value of x is print i.e. 5 after, it is increase.

Unary operators are solve right to left.


Q.1 Solve the expression in C language compiler ,assuming x,z are integer variables:
z = x++ + x++
where x=7
Ans.

9.06.2011

C Operators

What is operators?
In simple word operators are those which operator anything like as data,maths,information etc i.e.. When we talking about C operators, i want to say you that C is very rich in operators. Operators tells to compiler that what do with data. There are mainly operators in c as following:
  1. Logical Operators
  2. Bitwise Operators
  3. Relational Operators
  4. Assignment Operators
  5. Sizeof Operators
  6. Increment and Decrement operators
  7. Comma operators
  8. Type cast operator
  9. Conditional operators or ternary operators
Sometime operators are divided according numbers of operands. So there are three types of operators as following : 
Operators

Unary Binary Ternary
operand single double third
works right to left left to right left to right
Example_1 ++ , -- +, -, *, / ? :
Example_2 ! , ~ && , ||


All of these above operators we discuss step by step in next chapters.