Programming in "C‟ | State categories of function. Describe any one with example.

 The different categories of functions are: 

1. Function without arguments without return type

2. Function without arguments with return type

3. Function with arguments without return type

4. Function with arguments with return type 

Function without arguments without return type: Here the function will not return any value and it will not have any argument.

Example:

#include<stdio.h>

#include<conio.h>

void printNum();

void main() 

{

  printNum();

  getch();

}

void printNum() 

{

int i = 10;

printf("%d",i);

}

--------------------------------------------------
Function without arguments with return type: Here the function will return a value from the function but it will not have any arguments.
Example:
#include<stdio.h>
#include<conio.h>
int printNum();
void main() 
{
   int i = printNum();
   printf("%d",i);
   getch();
}
int printNum() 
{
   int i = 10;
   clrscr();
   return i;
}
------------------------------------------------------
Function with argument without return type: Here the function takes values as arguments but it does not return any value
Example:
#include<stdio.h>
#include<conio.h>
void printNum(int);
void main() 
{
   int i = 10;
   clrscr();
   printNum(i);
   getch();
}
void printNum(int i) 
{
printf("%d",i);
}
----------------------------------------------------------
Function with arguments with return type: Here the function takes values as arguments and returns value.
Example:
#include<stdio.h>
#include<conio.h>
int printNum(int);
void main() 
{
  int i = 10;
  int sq=0;
  clrscr();
  sq = printNum(i);
  printf("%d",sq);
  getch();
}
int printNum(int i) 
{
   int s = i*i;
  return s;
}

Post a Comment

0 Comments