Hello
In C++ you can do the following:
int x = 5
cout << x;
// prints 5
int* px = &x;
(*px)++;
cout <<x;
// prints 6
Is there an equivalent construct in Java
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In order to do this, you have to create an object that contains an int. Then, you can pass around a reference to that object, and you can increment the int that’s in that object. But there’s no way that you can have another reference to the same int and increments in one will increment the other — unless both cases are references to the same wrapper object.