+ 2
What does ++a or --a mean
8 Respuestas
+ 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++
+ 6
https://code.sololearn.com/W7X805sc4DPC/?ref=app
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
0
Asking not about a++ but about ++a
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.
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