How to call a function in c programming

 In c there are two types of functions:
1. Predefined functions
2. User defined function

Calling of predefined function:
    Too call predefined function is very easy. You have to include the header file where predefined function and call that function by passing the parameters to it according to its prototype.

For example:
Function sqrt has been defined in the header file math.h and its prototype is:

double sqrt(double)

That is takes one parameter which is double type data and returns a double type data. Program:

int main(){
    double a = 64;
    double b;
    //Calling of sqrt function
    b = sqrt(a);

    return 0;

Calling of user defined function:
To call user defined unction is same as pre defined function. In this case you have to write function declaration and function definition before the calling of function. For example:

long square(long); //Function declaration

int main(){
    long num = 5;
    long val;

    //calling of function
    val = square(num);


    return 0;

//Function definition
long square(long a){
    return (a * a);


Salem said...

I came across this site while searching for some practice problems in C. And your site is one of the best sites I have ever seen. You must be a great teacher. You are doing a great job. Keep it up!


KARAN said...

The best site i have seen in my total experience. hats off to you guys.