User defined Functions

Function


Hi Everyone

Hi Family I hope so you all are fine and doing your work during this pandemic of covid-19. I hope so you all are safe and all are stay at your home. I hope so my family will take my advice seriously and my family will stay in their own home for sometime so that they can protect themselves. I feel that you are my family so i had given this advice if you don't like it so please forgive me for giving this suggestion. So Today we are going to make a basic knowledge about functions in c programming. So without wasting your time let's get started.

So functions are those who receives argument and do some process on the arguments and then return the result to calling one. Using function you can understand the concept of code reusability. Using functions you can reduce your code and you can use it for many times. Printf is  a function you can use it for more than 100 times in practical so that you can save the code means if you don't use printf than you have to write whole functions code but if you use printf so you have to write only one life for calling the function. So there are 4 types of functions. Based on arguments and return type there are basic four or five types.
1.function without argument without return type

In this you have to only call the function it will do all work but not take any argument and won't return any thing.
Ex.
#include<studio.h>
void function()
{
   printf("Hi family");
 }
void main()
{
function();
}
It will simply print Hi family so here no argument is passed and nothing is returning.

2..function with argument without return type

In this you have to only call the function it will do all work but it will take argument and won't return any thing.
Ex.
#include<studio.h>
void function(int d)
{
   printf("Hi family %d",d);
 }
void main()
{
function(5);
}
It will simply print Hi family 5 so here argument is passed and but nothing is returning.
3..function without argument with return type

In this you have to only call the function it will do all work but not take any argument and will  return any thing.
Ex.
#include<studio.h>
int function()
{
   int d=4;
   printf("Hi family");
   return d;
 }
void main()
{
int d;
d=function();
printf("%d",d);
}
It will simply print Hi family4 so here no argument is passed and but it is returning.

4.function with argument with return type

In this you have to only call the function it will do all work but take an argument and will  return something.
Ex.
#include<studio.h>
int function(int d)
{
 
   printf("Hi family");
   return d*d;
 }
void main()
{
int d;
d=function(4);
printf("The square of 4 is : %d",d);
}
It will simply print Hi familyThe square of 4 is : 16 so here an argument is passed and it is returning.

5.function with argument with multiple return type

In this you have to only call the function it will do all work but not take any argument and will  return any thing.
Ex.
#include<studio.h>
int function(int d)
{
   printf("Hi family");
   return d>0?1:0;
 }
void main()
{
int d;
d=function(4);
if(d)
printf("The number is greater than 0 %d",d);
else
printf("The number is less than 0 %d",d);
}

It will simply print Hi family4 so here no argument is passed and but it is returning.
Here I have used ternary  operator it will work as if ...else if condition is true than part after ? Will executed and if false than after : part will be executed.
So these are the types of function in c language.

Thanks for watching  blog thanks to my family thanks to every member of my family thanks.

                      Made by:Great lord shri krishna

Comments