what is the difference between ++a and a++
Answers
++a is a pre-increment operator, which means that it will increase value of a by 1 before executing the statement.
ex- int a=2,i;
i=++a;
this program will result in value of i = 3 as value of a was increased by 1 before execution of that statement
a++ is a post-increment operator, which means that it will increase value of a by 1 after executing the statement.
ex- int a=2,i;
i=a++;
this program will result in value of i = 2 as value of a was increased by 1 after execution of that statement
++a is a pre-increment operator, which means that it will increase value of a by 1 before executing the statement.
ex- int a=2,i;
i=++a;
this program will result in value of i = 3 as value of a was increased by 1 before execution of that statement
a++ is a post-increment operator, which means that it will increase value of a by 1 after executing the statement.
ex- int a=2,i;
i=a++;
this program will result in value of i = 2 as value of a was increased by 1 after execution of that statement