Ways to define a function in C

There are four major types of function definition


  • Takes nothing Returns something
  • Takes something Returns something
  • Takes nothing Returns nothing
  • Takes something Returns something
  • Takes nothing Returns nothing
 When a function has no arguments, it does not receive any data from the calling function. Similarly when it does not return a value, the calling function does not receive any data from the called function.
Syntax :
Function declaration : void function();
Function call : function();
Function definition :
                      void function()
                      {
                        statements;
                      }
// C code for  function with no
//  arguments and no return value
  
#include <stdio.h>
void value(void);
void main()
{
    value();
}
void value(void)
{
    int year = 1, period = 5, amount = 5000, inrate = 0.12;
    float sum;
    sum = amount;
    while (year <= period) {
        sum = sum * (1 + inrate);
        year = year + 1;
    }
    printf(" The total amount is %f:", sum);
}
Output:
The total amount is 5000.000000

No comments:

Post a Comment

Featured Post

Core and Advance Python

                      Language Fundamentals