Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Correct this Matlab program with arguments passed by value then by reference?

Here is an incorrect Matlab program:

void swap (int x, int y)

{

int z = x;

x = y;

y = z;

}

void main()

{

int x = 10, y = 11;

swap(x,y);

}

I know how to correct it, but i'm not sure in what way two versions of it would differ when accepting arguments passed by value and reference. Can anyone help?

Thanks.

2 Answers

Relevance
  • Anonymous
    1 decade ago
    Favorite Answer

    As far as I know, that code is not Matlab.

    It's C.

  • dimes
    Lv 4
    4 years ago

    Key theory: Java manages memory and shops documents in 2 distinctive techniques. The heap: An amorphous mass of bytes. whilst an merchandise is created, this is allotted from the heap. At any time any byte in the heap is the two in the unfastened area or this is area of an merchandise. The stack: each and each thread has a stack. The stack is the place the tactic parameters and native variables are saved. the only documents on the stack are primitives or a connection with an merchandise. A connection with an merchandise is on the order of the size the primitives. It purely holds adequate strategies to tell the java digital gadget (JVM) the place to discover an merchandise in the heap. once you collect your classification, the compiler places strategies into the class document for each literal string, i.e. "some consistent textual content fabric". a million. on your occasion, whilst the JVM lots a classification, like MyApp, into memory, it is going to use the literal string strategies in the class document to create a String merchandise in the heap for literal. 2. whilst the main significant approach is entered, the JVM will make room for any interior sight variable on the stack. on your occasion, str. It the executes the duty operator, putting the handle of the string merchandise into the interior sight variable. 3. To make the call to printMessage, the JVM will: a. Make room on the stack for yet another merchandise reference b. reproduction the handle of the out of str into the gap allotted in step a. c. pass administration to the printMessage approach. 4. In printMessage, the JVM executes the duty operator putting the handle of the "hi, there!" string into the gap allotted in step 3a. 5. The JVM reached the top of the tactic. administration returns to the place it became the main significant approach. each and all the gap allotted on the stack in 3a is tossed away. word how the contents of str weren't in any respect touched. this is declared the Java passes gadgets by utilising reference because of fact the only strategies that is going onto the stack is the "reference", the handle of the article. for this reason placing the fee of m in printMessage would not substitute the fee of str.

Still have questions? Get your answers by asking now.