My Profile
Active Members
TodayLast 7 Days
more...
Awards & Gifts
Online Exams
Fresher Jobs
Our fresher job section is exclusively for fresh graduates! Find jobs for freshers in major Indian
cities including Bangalore, Chennai, Hyderabad, Pune or Kochi
Resources
Find educational articles, blogs, discussion threads and other resources.
Colleges
Find details about any college in India or search for courses.
Advertisements
|
C Operators-Increment Operator
Posted Date: 12 Jun 2008 Resource Type: Articles/Knowledge Sharing Category: Computer & Technology
|
Posted By: Girish Patil Member Level: Diamond Rating: Points: 4
|
|
|
|
INCREMENT OPERATOR Introduction You can increment or decrement the value of variable using the increment or decrement operator. These operators can be applied only to variables and they can be applied using prefix form or postfix form.
Program #include
main( ) { int I,j,k; i = 3; j =4; k = i++ + --j; printf("i = %d, j = %d, k = %d",i,j,k); }
Input i =3, j = 4.
Output i = 4, j = 3, k = 6.
Explanation When the prefix form is used, the value of the variable is incremented/decremented first and then applied. In the postfix form, the value is applied and only after the assignment operator is done is the value incremented or decremented.
Suppose you write
i = 3; j =4; k = i++ + -j;
you will get the value of k as 6, i as 4 and j as 3. The order of evaluation is as follows:
i gets the value 3.
j is decremented to 3.
k gets the value 3 + 3.
i is incremented.
Suppose you write
i = 5; i = i++ * i++
Then you will get the value of i as 27. This is because first the value 5 is used as to make i = 25 and then i is incremented twice. The increment and decrement operators have higher priority than the arithmetic operators
|
Responses
|
No responses found. Be the first to respond and make money from revenue sharing program.
|
|
|