You are on page 1of 2
‘wera, 1242 PM ‘What isthe diferance between ++i and itt in ©? What is the difference between ++i and i++ in c? In C, +* and — operators are called increment and decrement operators. They are unary operators needing only one operand. Hence ++ as well as -- operator can appear before or after the operand with same effect. That means both i++ and ++i will be equivalent. 15; ints printf ("%d",i); and iss Hi; print#("%d" yi); both will make i=6. However, when increment expression is used along with assignment operator, then operator precedence will come into picture. 53 fait In this case, precedence of = is higher than postfix ++. So, value of incrementing i, Here j becomes 5 and i becomes 6. is assigned to i before jattis In this case, precedence of prefix ++ is more than = operator. So i will increment first and the incremented value is assigned to j Here i and j both become 6. #include int main() { int i-5,45 jritts printf ("\nafter postfix increment i=%d j= i=55 ij printf ("\n after prefix increment i return 0; id", 4,5)5 is 2i,5)5 } The output is tps: tutrialspoint.comvhatis-he-liference-between-plusplus-and-plusplus-in-c we ‘wera, 1242 PM ‘What isthe diferance between ++i and itt in ©? after postfix increment after prefix increment hitps:lwwntutrialspoint comwhatis-he-di nce-between-plusplusiane:iplusplusin-c

You might also like