Function Declaration and Prototype

Every function in C program should be declared before they are used. Function declaration gives compiler information about function name, type of arguments to be passed and return type.

The syntax is shown below

return_type function_name(type(1) argument(1),....,type(n) argument(n));
Here , Return-Type: Data type of the result returned, (use void if nothing returned), Function-Name: Any valid Identifier, Parameter list: Comma separated list of arguments., Data type needed for each argument, If no arguments, use void or leave blank'

Example

void Display(void);
int print_data();
xyz(); // default return type is int
double abc(int, int, char, float*);
int absolute(int);
void print_array(float*, int, int);

Function Call

Control of the program cannot be transferred to user-defined function unless it is called
invoked. The syntax is shown below

function_name(argument(1),....argument(n));
Function Definition
Function definition contains programming codes to perform specific task.

The syntax is shown below:

return_type function_name(type(1) argument(1),..,type(n) argument(n))
{
//body of function
}

Program to Print a sentence using function.

#include<stdio.h>
void display(); //function declaration
void main()
{
display(); //function call
}
void display() //function definition
{
printf("C Programming");
return;
}
Function Declaration and Prototype Function Declaration and Prototype Reviewed by Unknown on 04:47 Rating: 5

No comments:

Powered by Blogger.