Jump to content

Definition of Subroutine

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
hetra

hetra

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 297 posts
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.

#2
exicute

exicute

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 398 posts
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:

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.
Posted Image
My Tutorials|Build A Computer|Cat 5E|

#3
dcs

dcs

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 775 posts

Hunter100 said:

I would like to know what a subroutine is in C++ (and anything else for that matter).
A search engine is well suited to such questions.
Subroutine - Wikipedia, the free encyclopedia

#4
exicute

exicute

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 398 posts

dcs said:

A search engine is well suited to such questions.
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?
Posted Image
My Tutorials|Build A Computer|Cat 5E|

#5
hetra

hetra

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 297 posts
Thanks again exicute, that's exactly what happened.