+ 1

What's the Difference between (a++),(++a) and (--a), (a--) in C#?

13th Nov 2023, 7:46 AM
Nesa Cheraghi
Nesa Cheraghi - avatar
6 Answers
13th Nov 2023, 7:54 AM
Gulshan Mahawar
Gulshan Mahawar - avatar
+ 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
13th Nov 2023, 8:04 AM
Alhaaz
Alhaaz - avatar
+ 2
Thank youuu ^~^
13th Nov 2023, 7:58 AM
Nesa Cheraghi
Nesa Cheraghi - avatar
+ 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
13th Nov 2023, 2:33 PM
Ayush Raj
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
15th Nov 2023, 2:01 AM
Soma Swarna
Soma Swarna - avatar
0
++a means increment it first and then return a while a++ means return a first and then increment it
15th Nov 2023, 2:52 AM
ADITYA MISHRA
ADITYA MISHRA - avatar