Hello,
I would like to know what a subroutine is in C++ (and anything else for that matter).
I know it's like a miniprogram in a program but not much else.
Thanks.
Definition of Subroutine
Started by hetra, Feb 12 2010 08:27 PM
4 replies to this topic
#1
Posted 12 February 2010 - 08:27 PM
|
|
|
#2
Posted 12 February 2010 - 08:58 PM
A subroutine is a portion of code within a larger program, which performs a specific task.
I'm not familiar with C++ syntax, but C is very close to it.
Take the following C Code:
This would be the subroutine:
This would be a (one of two in this program) statement:
In short, a subroutine is any function that can be called within a section of the program. A subroutine first obtains one or more values from the program and then returns a value. (In this case, it returns a boolean value of nonzero, true.) If I used the while function to check if a variable was true for a certain condition the value that the function called would obtain would be the value of said variable then it would return the appropriate boolean value.
At least, that is my understanding of a subroutine.
Hope this helps,
Exicute.
I'm not familiar with C++ syntax, but C is very close to it.
Take the following C Code:
int main ()
{
while (1 == 1)
{
printf("Hello World");
}
return 0;
}
This would be the subroutine:
while (1 == 1)
{
printf("Hello World");
}
This would be a (one of two in this program) statement:
printf("Hello World");
In short, a subroutine is any function that can be called within a section of the program. A subroutine first obtains one or more values from the program and then returns a value. (In this case, it returns a boolean value of nonzero, true.) If I used the while function to check if a variable was true for a certain condition the value that the function called would obtain would be the value of said variable then it would return the appropriate boolean value.
At least, that is my understanding of a subroutine.
Hope this helps,
Exicute.
#3
Posted 12 February 2010 - 09:37 PM
Hunter100 said:
I would like to know what a subroutine is in C++ (and anything else for that matter).
Subroutine - Wikipedia, the free encyclopedia
#4
Posted 12 February 2010 - 09:40 PM
dcs said:
A search engine is well suited to such questions.
Subroutine - Wikipedia, the free encyclopedia
Subroutine - Wikipedia, the free encyclopedia
Good point was going to add that to my reply, but perhaps he searched and did not understand the content in the way that it was presented and just needed a different (Simplified.) explanation?
#5
Posted 12 February 2010 - 11:11 PM
Thanks again exicute, that's exactly what happened.


Sign In
Create Account


Back to top










