+ 2

What does ++a or --a mean

31st May 2017, 7:09 AM
Pranjal
Pranjal - avatar
8 ответов
+ 2
the main difference between --a and a-- is that --a is pre decrement while a-- is post decrement. pre decrement Means first the value is decreased n new value is assigned while in post decrement, the function or operator you are using will take the normal value of variable and after it's done , the decrement will take place. Ex. a=1; cout<<--a<<endl; // pre decrement a=2; cout<<a--<<endl; //post decrement, this will print a first n then change value cout<<a; //now will print the changed value Output: 0 2 1 SAME CASE WITH PRE/POST INCREMENT i.e. ++a and a++
1st Jun 2017, 9:56 AM
Saurabh Panda
Saurabh Panda - avatar
31st May 2017, 9:08 AM
Hatsy Rei
Hatsy Rei - avatar
+ 6
https://code.sololearn.com/W7X805sc4DPC/?ref=app
31st May 2017, 9:09 AM
Art456
Art456 - avatar
31st May 2017, 7:16 AM
TakshakSH
TakshakSH - avatar
0
++ is the increment operator -- is the decrement operator say if a=10 a++ = 11 = a+1 a-- = 9 = a-1 not only c++ but in all programming languages
31st May 2017, 7:19 AM
onekpsc
0
Asking not about a++ but about ++a
31st May 2017, 12:39 PM
Pranjal
Pranjal - avatar
0
 ++a is called Pre Increment. ++a will increment the value of a, and then return the incremented value. say If. i = 1; j = ++i; (i is 2, j is 2)  In a for loop, you can use any one.. no matter. It will execute your for loop same no. of times. For example, for(i=0; i<5; i++) printf("%d ",i); And for(i=0; i<5; ++i) printf("%d ",i); Both the loops will produce same output. ie 0 1 2 3 4. It only matters where you are using it. for(i = 0; i<5;) printf("%d ",++i); In this case output will be 1 2 3 4 5.
12th Jun 2017, 1:48 PM
Asish Samantaray
Asish Samantaray - avatar
0
++a means it increments 'a' before its value is used a++ means it increments 'a' after its value has been used similarly --a means it decrements 'a' before its value is used
3rd Jul 2017, 11:43 AM
Manisha
Manisha - avatar