Declaration Vs definition
Declaration Vs definition



The declaration of a function specifies the return and parameter types. The definition specifies the part of the program associated to the function, i.e. the statement between { }.

Up to now, we have always done the declaration and the definition simultaneously, but declaration can be done before the definition. This is useful because a function can be called at a given location in the program only if the declaration we done before.

#include <iostream>
int function1(int x);
int function2(int x) {
if(x == 0) return 0;
else return function1(x-1);
}
int function1(int x) {
if(x == 0) return 1;
else return function2(x/2);
}
int main(int argc, char **argv) 
{cout << function1(15) << ’\n’;
}
Designed By Blogger Templates | Templatelib & Distributed By Blogspot Templates