Saturday, December 11, 2010

A Real Function!

Enough dilly-dally, let's see a real, working, C++ function that actually does something! Suppose we need a function that, adds two numbers and return their sum..

int sum(int num1,int num2)
{
              return(num1+num2);
}


This is our function. Everytime it takes two parameters (integers) and return their sum..
In our main we call it like this..


int main()
{
                    int a=9;
                    int b=8;
                    int c=sum(a,b);
                    cout<<c<<endl;  // c=17
                    return 0;
}

No comments:

Post a Comment