Page 6 - Sample_test_Float
P. 6
6 Functions and Pointers
Function declaration is similar to a variable declaration. It provides the following information to the compiler.
It should contain three parts.
1. The return type(the data type of the result/output)
2. The function name
3. The parameter list(the data type of the inputs)
Some important points in function declaration:
• Prototype declaration should always end with a semicolon.
• Parameter list is optional.
• Default return type is integer.
Note: if there are no parameters or return type in a function, you can specify as void.
Syntax
Return Type Function Name(Argument Type1, Argument Type2, ...., Argument TypeN);
Example
If you are going to create a function name add, that accepts two integer values as input, adds the two
values and gives the result as integer value, then the function declaration would be as follows:
int add(int,int);
Few more examples of function declaration are given below:
Function with no argument and integer as return type
int getValue(void);
Function with integer argument and integer as return type
int square(int);
Function with no argument and no return type
void display(void);
Note:
• If function definition is written after the main function, then we need only Prototype Declaration in Global
Declaration Section.
• If function definition is written before the main function, then we don’t need write Prototype Declaration.
• Function’s declaration doesn’t reserve any memory space.
Example Program
Function Definition Written After Main
#include<stdio.h>
void show();// Function Declaration
void main()
{
displayMessage();
}
void show()
{
printf(“After Main”);
}

