+ 1
What's the Difference between (a++),(++a) and (--a), (a--) in C#?
6 Answers
+ 5
It's related to postfix and prefix increment of an value.
https://www.sololearn.com/Discuss/3082740/?ref=app
https://www.sololearn.com/Discuss/2870839/?ref=app
https://www.sololearn.com/Discuss/2544528/?ref=app
+ 3
it is known as prefix and postfix
a++/a-- , first print the var and than assign (+1/-1) into it
++a/--a , first assign (+1/-1) and than print it
eg
int a=1;
print(a++)
*output*->1
int a=1;
print(++a)
*output*->2
+ 2
Thank youuu ^~^
+ 2
Actually this topic is under of increment and decrement operators
a++ and a-- : it is a post form of increment and decrement operators so it will be assign first then increment.
for instance-
int main()
{
int a=5,b;
b=a++;// it has assigned b=5 first then increment .
printf("%d\n",b);
printf("%d",a);
return 0;
}
Output:
b=5
a=6
similarly
++a and --a : it is a pre form of increment and decrement operators so it will be increment and decrement first then assign.
for instance:
int a=5, b;
b=--a// it has decrement first(I.e a=4) then Assigned
printf("%d\n",b");
Output:
b=4
I hope I answered your question
0
a++ and a-- is post increment ani decrement .First it will assign and then operation
--a and ++b is pre increment and decrement . first it will operate and assign the value
0
++a means increment it first and then return a while a++ means return a first and then increment it