Code About Us Tutorial


  Functions
    What are Functions?
    Function Definition
    Functions as Parameters to Functions
    Return Values
    Separating Functions
    Passing By Value
    Passing By Reference
    Passing By Pointer
    Inline Functions
    Overloading Functions


   
 

Home > Functions > Separating Functions

November 26, 2009 7:15 pm

   

Separating Functions

Separating Function Definitions Function definitions are often compiled independently in separate files. For example, all the functions declared in the standard C Library are compiled separately. One of the reasons for separating them, is “hiding the information” which means, information that is necessary for the complete compilation of the program but not essential to the programmer’s understanding of the program is hidden. In other words, the program will be easier to modify and understand if everything is broken down into chunks of information rather then one huge mess of code. Many programmers that have been programming for several years think “information hiding” facilitates the understanding and therefore the success of large software projects.” Here is an example of what I’m talking about:

 

 
//main.cpp

int max(int, int); //prototype

main() { int m, n; do { cin >> m >> n; cout << max(m,n) << endl; } while (m != 0); }

//new file, named max.cpp //returns the larger of the two given integers:

int max(int x, int y) { if (x < y) return y; else return x; }

Now that you know the basics of functions you can write your own simple tasks and develop them into functions. Please Rate this Code:


    Comments for: Separating Functions
  There are NO user contributed comments for Separating Functions.



Add Comment:
Name:
Email:


 «