+ 5

What is the meaning of ++b

3rd Apr 2018, 2:41 PM
varun pawar
13 ответов
+ 7
case1) int a=++b; //it mean value of b increases by 1 & a=b+1; case2) b=++b; //it means value of b increased by 1 //but if b++ here , then no increment
3rd Apr 2018, 2:47 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 4
Pre-increment. Increase 'b' by one and operate.
3rd Apr 2018, 2:42 PM
Fata1 Err0r
Fata1 Err0r - avatar
+ 4
it counts the integer b + 1
3rd Apr 2018, 2:42 PM
TrueJu
TrueJu - avatar
+ 1
i had problem with the following code a=2; b=3; b=a++; cout<<++b;
3rd Apr 2018, 3:00 PM
varun pawar
+ 1
@Varun When in doubt, create logs in your code to see values. https://code.sololearn.com/ceiEl4h4gKy5/#cpp #include <iostream> using namespace std; int main() { int a=2; int b=3; // Display our initial values. cout << "Variable a = " << a << "\n"; cout << "Variable b = " << b << "\n"; b=a++; cout << "b = a++ is equal to " << b << "\n"; // Because a++ is post-increment, it increases AFTER we assigned the value to 'b' cout << "Afterward 'b' is equal to " << b << endl; cout << "Afterward 'a' is equal to " << a << endl; // In this case, we increase the value of b BEFORE we assign it, so we get 3. cout << "Pre-increment 'b' variable to get " << ++b << "\n"; cout << "End result for b: " << b << endl; return 0; } ::: OUTPUT ::: Variable a = 2 Variable b = 3 b = a++ is equal to 2 Afterward 'b' is equal to 2 Afterward 'a' is equal to 3 Pre-increment 'b' variable to get 3 End result for b: 3
3rd Apr 2018, 3:20 PM
Fata1 Err0r
Fata1 Err0r - avatar
+ 1
Hi dude ! It's means that before using the variable's value the Compiler increase the value by one
3rd Apr 2018, 4:17 PM
Sahil Verma [Inactive]
Sahil Verma [Inactive] - avatar
+ 1
The solution of about problem is that In 3rd line b=a++ means the value of a++ goes into b so now the value of b is 2 and when while cout before read the variable by Compiler it increases by 1 so the net value is 3 The confusion may be in a++ =2 It is because in starting the value of a is 2 and that value goes to b now if we use 'a' further so we have to put the value of a =3
3rd Apr 2018, 4:22 PM
Sahil Verma [Inactive]
Sahil Verma [Inactive] - avatar
+ 1
Brother first read the whole conversation and then give your views
16th Apr 2018, 11:25 AM
Sahil Verma [Inactive]
Sahil Verma [Inactive] - avatar
0
It means the value of b increases by 1.It is pre-increment.
6th Apr 2018, 2:45 PM
Adesina
Adesina - avatar
0
increment
8th Apr 2018, 3:11 AM
Harsh Mendpara
Harsh Mendpara - avatar
0
++b is preincrement operator. Actually it first increments a given value,then the incremented value is assigned to the variable
16th Apr 2018, 5:26 AM
DEBAYAN BHAUMIK
DEBAYAN BHAUMIK - avatar
- 2
anyone hacker here?
7th Apr 2018, 10:43 AM
Sakha Nego
Sakha Nego - avatar
- 3
prefix increment operator
6th Apr 2018, 9:25 AM
Aye Aye Mar