Skip to main content
added 1 characters in body
Source Link
hvgotcodes
  • 120.6k
  • 33
  • 209
  • 237

You can't directly. The closest you can get is to put the value in an object, and pass the reference (by value, so the reference gets copied) into the method.

void func()
{
  int x = 3;
  int[] holder = [x];
  add_one(holder);
  // now holder[0] is 4.  x is still 3.
}

// container here is a copy of the reference holder in the calling scope.
// both container and holder point to the same underlying array object
void add_one(int[] container)
{
    container[0]++;
}

Here I use an array, but the wrapper an by onycan be any object.

You can't directly. The closest you can get is to put the value in an object, and pass the reference (by value, so the reference gets copied) into the method.

void func()
{
  int x = 3;
  int[] holder = [x];
  add_one(holder);
  // now holder[0] is 4.  x is still 3.
}

// container here is a copy of the reference holder in the calling scope.
// both container and holder point to the same underlying array object
void add_one(int[] container)
{
    container[0]++;
}

Here I use an array, but the wrapper an by ony object.

You can't directly. The closest you can get is to put the value in an object, and pass the reference (by value, so the reference gets copied) into the method.

void func()
{
  int x = 3;
  int[] holder = [x];
  add_one(holder);
  // now holder[0] is 4.  x is still 3.
}

// container here is a copy of the reference holder in the calling scope.
// both container and holder point to the same underlying array object
void add_one(int[] container)
{
    container[0]++;
}

Here I use an array, but the wrapper can be any object.

edited body
Source Link
hvgotcodes
  • 120.6k
  • 33
  • 209
  • 237

You can't directly. The closest you can get is to put the value in an object, and pass the reference (by value, so the reference gets copied) into the method.

void func()
{
  int x = 3;
  int[] holder = {x};[x];
  add_one(holder);
  // now holder[0] is 4.  x is still 3.
}

// container here is a copy of the reference holder in the calling scope.
// both container and holder point to the same underlying array object
void add_one(int[] container)
{
    container[0]++;
}

Here I use an array, but the wrapper an by ony object.

You can't directly. The closest you can get is to put the value in an object, and pass the reference (by value, so the reference gets copied) into the method.

void func()
{
  int x = 3;
  int[] holder = {x};
  add_one(holder);
  // now holder[0] is 4.  x is still 3.
}

// container here is a copy of the reference holder in the calling scope.
// both container and holder point to the same underlying array object
void add_one(int[] container)
{
    container[0]++;
}

Here I use an array, but the wrapper an by ony object.

You can't directly. The closest you can get is to put the value in an object, and pass the reference (by value, so the reference gets copied) into the method.

void func()
{
  int x = 3;
  int[] holder = [x];
  add_one(holder);
  // now holder[0] is 4.  x is still 3.
}

// container here is a copy of the reference holder in the calling scope.
// both container and holder point to the same underlying array object
void add_one(int[] container)
{
    container[0]++;
}

Here I use an array, but the wrapper an by ony object.

added 29 characters in body
Source Link
hvgotcodes
  • 120.6k
  • 33
  • 209
  • 237

You can't directly. The closest you can get is to put the value in an object, and pass athe reference (copy of)by value, so the reference gets copied) into the method.

void func()
{
  int x = 3;
  int[] holder = {x};
  add_one(holder);
  // now holder[0] is 4.  x is still 3.
}

// container here is a copy of the reference holder in the calling scope.
// both container and holder point to the same underlying array object
void add_one(int[] container)
{
    container[0]++;
}

Here I use an array, but the wrapper an by ony object.

You can't directly. The closest you can get is to put the value in an object, and pass a (copy of) the reference into the method.

void func()
{
  int x = 3;
  int[] holder = {x};
  add_one(holder);
  // now holder[0] is 4.  x is still 3.
}

// container here is a copy of the reference holder in the calling scope.
// both container and holder point to the same underlying array object
void add_one(int[] container)
{
    container[0]++;
}

Here I use an array, but the wrapper an by ony object.

You can't directly. The closest you can get is to put the value in an object, and pass the reference (by value, so the reference gets copied) into the method.

void func()
{
  int x = 3;
  int[] holder = {x};
  add_one(holder);
  // now holder[0] is 4.  x is still 3.
}

// container here is a copy of the reference holder in the calling scope.
// both container and holder point to the same underlying array object
void add_one(int[] container)
{
    container[0]++;
}

Here I use an array, but the wrapper an by ony object.

added 58 characters in body
Source Link
hvgotcodes
  • 120.6k
  • 33
  • 209
  • 237
Loading
added 23 characters in body
Source Link
hvgotcodes
  • 120.6k
  • 33
  • 209
  • 237
Loading
edited body
Source Link
Eng.Fouad
  • 118.2k
  • 75
  • 326
  • 431
Loading
Source Link
hvgotcodes
  • 120.6k
  • 33
  • 209
  • 237
Loading