answersLogoWhite

0


Best Answer

A closed subroutine is a normal unit like a function in C or a method in Java. When a closed subroutine is called, the program branches to the file/section of code, executes, and then returns to the line after the calling line.

For example, if you had the following code in Java:

main(...) {

int a = 1;

int b = 4;

multiply(1,4);

System.out.println("done!");

}

multiply(int a, int b) {

int answer = 0;

for(int i = 0; i < 4; i++)

answer*=a;

return answer;

}

Over here, the main method executes until it reaches multiply(1,4) and then jumps to the function (declared below main) and executes that. After it finishes executing multiple, it returns to the line after the function call, which in our case is System.out.println, and executes that.

An open subroutine is a subroutine that adds the instruction to the already existing block of code. That is, it replaces the one line call with the entire set of instructions.

For example, if you had the following code:

start

save 1 in a

save 4 in b

multiply a b-times

end

The command "multiply a b-times" is an open subroutine because the command will add lines at compile time to the existing code to return the following (this is best understood when thinking of the code as machine code):

(translated from machine code)

start

save 1 in a

save 2 in b

ADDED CODE

save a * a in c

save c * a in d

save d * a in e

return e

end

As you can see, the "multiply" command has been replaced with the entire set of instructions (under ADDED CODE).

In short, an open subroutine adds lines to your main code while a closed subroutine is code stored in a separate block of code. Both subroutines are called with a single line of code.

User Avatar

Wiki User

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Difference between open subroutine and closed subroutine?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Computer Science

Define the difference between an open network and a closed network?

There are two kinds of 'household networks', Open and Closed. Open networks can be joined by anyone at anytime. Closed networks require permission to join. When you attempt to join a closed network, a notice is sent to the Closed Network's administrator requesting that you be allowed to join. That person will respond either accepting or denying your request. (remember, once you've joined a network, you cannot leave that network for 30 days - security reasons).


What is the difference between using open authentication and pre-shared keys?

Open authentication requires a password. Pre-shared keys do not require a password.


What are the differences between an open loop and closed loop injection molding machine?

The difference between open loop and closed loop injection moulding is to do with the type of control system used. An open loop system changes the input signal relative to the pre-defined perameters of the system. A closed loop system uses a feedback signal ie it takes information from a point in the process usually the end and sends it back to the start where the system adjusts the input accordingly. To fully understand this I would suggest getting a good book on control theory. I use 'Modern Control Engineering' by Katsuhiko Ogata. Many people also use Richard Dorf but I find Ogata easier to follow. AuthorOgata, Katsuhiko.TitleModern control engineering / Katsuhiko Ogata.


What is the difference between new and open on the computer?

The 'New' menu item allows you to create a new, blank document. The 'Open' menu item allows you to open an already existing document, rather than create a new one.


DIP switches are either open or closed?

Yes....that's right, they are either Open or Closed. Now for your personal setup, we can't know which they're supposed to be, you need to look up your motherboard specs to find that out. Why do allot of these questions sound like people are trying to get help with their Computer Science tests...??? This would be CompSci 101 tho

Related questions

What is the difference between an open and closed community?

one is open and the other is closed


What is the difference between open populations and closed populations?

the difference between open and closed population is that ...................................................................................................................................................................... go some where else to find the answer not on wiki awners.com


What is the difference between an open DNS and a closed DNS?

There is one major difference between an open DNS and a closed DNS. Open DNSs allow multiple users to connect easily while closed ones do not allow more users.


What is the difference between an open universe and a closed universe?

there is no difference. they are both 42.


What is the difference between shoes and sandals?

Shoes are closed in and Sandals are open.


What is the difference between open bases and closed bases in youth baseball?

N


The difference between private and public administration?

Public is open, private is closed.


What is the difference between a gutter and a sewer?

Gutters are normally open Sewer piping is closed


What is one difference between open and closed primary districts?

In open primary districts, voters can choose to participate in any party's primary regardless of their own party affiliation. In closed primary districts, voters can only participate in the primary of the party they are registered with.


What is the difference between closed heat pipe and open heat pipe?

Pressure rises in the tube.


What is the difference between a straight and an inlet?

an inlet has a closed end a straight is open both ends


What is the difference between open-source and closed-source software?

The answer is in the question itself. Open-source software has it's source code available to everyone. Closed-source software does not.