Function In C in Hindi | functions in c programming with examples

Function In C in Hindi | functions in c programming with examples

Function In CC Function ko ham isliye istemal karte hai taki hame ek hi code ko bar bar likhna na pade isliye c programming me ham function ko banante hai |

Function In C

Function Kiya Hai ? :- Function Line of code ya sub program hota hai inka ek group hota hai chota program ka us program me kitni bhi line ho sakti hai or inka aapna ek name & Features hota Hai Or Function ko Aap Program me Kahi bhi Call Ya Dobara Istemal kar Sakte Hai |

Function ko Kyo Istemal Karte hai ? :- Jab Ham koi code likhte hai to wo code main ke under hi execute hota hai | Lekin Jab koi program bahut Bada Ho Jaye Or koi code of line bar bar repeat ho rhi ho to ham function Bana Sakte hai isse program aashan ho jata hai |

Types of Function In C

Function Mainly 2 Tarah ke hote hai |

  1. Built In Function
  2. User Defined Function
function in c in hindi

Defining Functions

return_type function_name( parameter list )
{
   body of the function
}
  • Function Type ( return type ) :- Jab ham User defined function banate hai to hame pahle ye batana hota hai ki function konsi value return karega or function koi bhi value return kar sakta hai |
  • Function Name :- Jab Ham User Defined Function Banate hai To ham function ka name dete hai & uska name ham kuch bhi de sakte hai |
  • Parameter List ( Arguments ) :- Parameter List means hota hai ki use kitne inputs diye jayenge suppose agar ham ek 2 number addition ka program banate hai to ham 2 parameter pass karenge |

Example :

int add(int a , int b); 

Add to Two Number using function

#include<stdio.h>
#include<conio.h>

  int main()
  {
      int num1 , num2, result;
      printf("Enter The Two Number :");
      scanf("%d %d",&num1, &num2);
      
      //call function sum with two parameter
      result = sum(num1,num2);
      
      printf("Addition of two Number is :%d",result);
      return 0;
  }
  
  int sum(int num1, int num2)
{  
  int num3;
  num3 =  num1 + num2;
  return (num3);
}

Output:

Enter The Two Number :10 20
Addition of two Number is :30

Function Declarations in c

A – Function Header

int add(int a , int b);   # function definition

B – Function Body

# after header line
{
   # local variable
   # statements
   # return value statement
}

Example :- Find Max Value Using Function in c

#include <stdio.h>
 
/* function declaration */
int max(int num1, int num2);
 
int main ()
{

   /* local variable definition */

   int a = 100;
   int b = 200;

   int greater;
 
   /* calling a function to get max value */
   greater = max(a, b);
 
   printf( "Greater value is : %d\n", greater );
 
   return 0;
}
 
/* function returning the Greater between two numbers */
int max(int num1, int num2)
{

   /* local variable declaration */
   int result;
 
   if (num1 > num2)
      result = num1;
   else
      result = num2;
 
   return result; 
}

Output:

Greater value is : 200

Upper Diye gye output dekh kar aap program ko samanjh sakte hai|

Example 2 :- Find Max Value Using Function in c

#include <stdio.h> 

// An example function that takes two parameters 'x' and 'y' 

int max(int x, int y) 
{ 
	if (x > y) 
	return x; 
	else
	return y; 
} 

// returns integer. 
int main(void) 
{ 
	int a = 10, b = 20; 
        int m;
	// Calling above function to find max of 'a' and 'b' 
        m = max(a, b); 
	printf("Max Value is %d", m); 
	return 0; 
} 

Output :

Max Value is 20

Upper Diye gye output dekh kar aap program ko samanjh sakte hai|

Category of functions in c

C Programming Me Functions ko 4 category me bata gya hai |

  1. Function with Arguments and Return value
  2. Function with No Arguments and No Return Value
  3. Function with Arguments and No Return Value
  4. Function with No Arguments and Return Value

Example step by step :-

1 – Function with Arguments and Return value

int add(int a, int b);

2 – Function with No Arguments and No Return Value

void add(void);

3 – Function with Arguments and No Return Value

void add(int a ,int b);

4 – Function with No Arguments and Return Value

int add(void);

Function Call in c

  1. Call by Value
  2. Call By Reference

Call By Value :- Call by Value Means Ham Jab function ko call karenge to usko value supply krenge ya fir variable ka name supply karenge means waha par jo value hogi wo actual argument se copy ho kar formal argument me chali jayegi. lekin ye value 2 hogi 1 value jo actual argument ke pass hai or 1 iski value copy jo formal argument ke pass hai|

Example :

#include <stdio.h> 
void fun(int x) 
{ 
x = 50;    
} 

int main(void) 
{ 
	int x = 20; 
	fun(x); 
	printf("x = %d", x); 
	return 0; 
} 

Output:

x = 20

Upper Diye gye output dekh kar aap call by value program ko samanjh sakte hai|

Call By Reference :- Call By Reference Matlab ye keval address ko hold karta hai |

Example :

# include <stdio.h> 
void fun(int *ptr) 
{ 
	*ptr = 30; 
} 

int main() 
{ 
int x = 20; 
fun(&x); 
printf("x = %d", x); 

return 0; 
} 

Output:

x = 30
functions in c programming with examples

Dosto mujhe ummed hai ki aap functions in c programming ko acchi tarah se samanj gye honge agar aap ko ye post acchi lage to mere is website ko jarur follow kre or ha agar aap video bhi dekhna chahte hai to aap mere channel ko bhi subscribe kar sakte hai. channel ka link aapko home page par mil jayega |

Danish Ali

I Am a 1st Sem BCA Student & I have Skills C, C++ ,Python, HTML,CSS, Computer & Advance Hacking & Blogger & YouTuber.

Leave a Reply

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