- 2

Increament operators

what does this really mean ? and where we can use it ? any details ? thanks

2nd May 2018, 3:14 AM
AMANULLAH
AMANULLAH - avatar
12 Answers
+ 4
There would be a difference, you are overthinking this it feels like. num3 = num2 ++ + ++num1 which translates to num3 = num2 + (num1 +1) (num2 + 1) Again, Pre (before) Post (After)
3rd May 2018, 6:44 AM
Josh Schweigert
Josh Schweigert - avatar
0
ty
2nd May 2018, 3:42 AM
AMANULLAH
AMANULLAH - avatar
0
but didnt understand the difference between of 2++ & ++2 or something like this
2nd May 2018, 4:18 AM
AMANULLAH
AMANULLAH - avatar
0
Think about it as pre and post. Pre: Before. Increment the value before using it in the statement. Post: Increment the value after using it in the statement. So cout << ++2 would output 3 because we increment 2 BEFORE using it in the cout statement. cout << 2++ would output 2 then increment 2 by 1 to 3 AFTER using the 2 in the cout statement.
2nd May 2018, 7:36 AM
Josh Schweigert
Josh Schweigert - avatar
0
x=5 y=x++ cout<<y; is 6? if yes then what about this ? x=5 y=++x cout<<y; ??? Josh Schweigert
2nd May 2018, 7:42 AM
AMANULLAH
AMANULLAH - avatar
0
no opposite.
2nd May 2018, 8:08 AM
Josh Schweigert
Josh Schweigert - avatar
0
Josh Schweigert can u pls expain this issue in any other way ?
2nd May 2018, 8:10 AM
AMANULLAH
AMANULLAH - avatar
0
You have the exact thing just backwards. I don't know how to be any more clear.
2nd May 2018, 8:21 AM
Josh Schweigert
Josh Schweigert - avatar
0
int num1; int num2; int num3; num1=100; num2=++num1; num3=num2++ + ++num1 in here in num3 the value of num2 is 101+1=102 + 1+100 which is equals to 203... my question is that num2++ or ++num2 is the same ? because both adds 1 to the value. if yes then what is the difference... Josh Schweigert
2nd May 2018, 4:53 PM
AMANULLAH
AMANULLAH - avatar
0
When the ++ sign is before the value then it is called pre increment which means the value is incremented before termination and if the ++ sign is after the value then the value is incremented at the next step of termination. Hope it helps you
21st Sep 2019, 6:37 PM
Ritam Dey
Ritam Dey - avatar
0
Quisiera hacer una tabla de multiplicar del 1 al 10, y tengo hecho <?php //$b es el multiplicando $b = array(1,2,3,4,,5,6,7,8,9); $producto = 0; //$u es el multiplicador $u = 1; for ($u = 1; $u <= 10; $u++) { $producto *= $b[$u]; } echo "El valor del producto es = $producto . <br />; ?> El problema que tengo es que no me funciona la lĂ­nea $producto *= $b[$u]. CĂłmo se harĂ­a? Gracias
28th Feb 2020, 12:25 PM
ppliman