Loading...
C

Function Declaration

Function Declaration or Prototype : Like variable and an array, a function must also be declared before it is called. A function declaration tells the compiler about a function name and how to call the function. The body of the function can be defined separately.
Below are some important things that to be noted related to prototype declaration :-

  • It tells name of the function, return type of the function and arguments list related information to the compiler.
  • Prototype declaration always ends up with semicolon.
  • Default return type is integer
  • Parameters list is optional.

A function declaration consists of 4 parts.

  1. return -type
  2. function name
  3. parameter list
  4. terminating semicolon

Syntax :

return_type function_name (parameter_list);
Example: int sum(int,int);
int add(float,int);
Return_type:- Return type specifies the type of value (int, float, char, double) that function is expected to return to the program calling the function.
Function_name:- It specifies the name of function. The function name is any valid C identifier and therefore must follow the same rule of formation as other variables in C.
Parameter_list:- The parameter list declares the varables that will recieve the data sent by calling program. They often referred to as formal parameters. These parameters are also pass values to calling program.

Leave a Reply

Your email address will not be published. Required fields are marked *