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 > What are Functions?

November 29, 2009 7:28 pm

   

What are Functions?

You are all probably wondering what is a function. Well you can think of functions as little packages of code -- they do the work, but they can be reused later. This makes programming easier, as you will need to write less code. Before we get into the aspects of writing a function in C++, we have to understand how to declare a function using a prototype. The declaration tells the compiler:

 

 
  • the name,
  • return type, and
  • parameters of the function.
For instance, say you want to write a prototype for a function that adds two numbers:

 

 
int addTwoNumbers ( int n1, int n2 );       //prototype

Basically, in the function prototype you must include a return type, the name of the function and if it has parameters or not (in the case of a function with no parameters you would write void as the return type and just leave the ( )’s blank instead of int as shown above.)Please Rate this Code:


    Comments for: What are Functions?
Annonymouse User says:
sad sad sadfdf sasdc sdfvdfc sadc sd

Annonymouse User says:
sad sad sadfdf sasdc sdfvdfc sadc sd says:
I had no clue about functions before coming to this website and I STILL DON\'T HAVE A CLUE about functions now that I am leaving the website.

A.D [ad@hotmail.com] Posted: 7 times. says:
Explanation is good but it could be put in better order.

A.D [ad@hotmail.com] Posted: 7 times. says:
Explanation is good but it could be put in better order. says:
im trying very hard to learn this.. put more examples!!!




Add Comment:
Name:
Email:


 «2» THINKQUEST TEAM C0111571 © 2001. All Rights Reserved.