Can someone explain the concept of pre and post increment in C?

Please explain ++i and i++ use with example. It confuses me many times, which one increment its value first and when assigned?

  • Aditi
  • 27 Nov
  • 4207 Views
  • 3 Answers
Your Answer

++i is pre increment operator and i++ is a post increment operator in ++i first i is incremented to i+1 and its value is fetched . in i++ first value of i is fetched then i is incremented to i+1 after execution i.e. incremented value effect can be seen in next statement . let us consider an example where int i=10; int j =i++; //j will contain value of =10 and i will we incremented to 11 vs int j = ++i; // i will be incremented first and then its value will be assigned to j i.e j will contain 11.

-1
c programming
Practice Mock Test
c programming