Function In C++ in Hindi – C++ Function in Hindi 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++ in Hindi
Contents
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 |
Read Also :- Arrays & Multidimensional Arrays
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++ in Hindi
Function Mainly 2 Tarah ke hote hai |
- Built In Function
- User Defined Function

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 |
Advantage Of Function in C++ In Hindi
- Function Mai Likha Gaya code bar-bar Likhna Nhi Padta Hai |
- Function Programmer ka Time or Program ki space bachata hai |
- Long Ya Big Program ko Chote – Chote Function Mai Divide Kiya Ja Sakta Hai |
- Agar Program Mai Kahi Par error Aa Jaye To Use Aasani Se Nikala Ja Sakta Hai |
- Jaha Par Jarurat Ho Waha Par function Ko Bar-Bar call Kiya Ja Sakta Hai |
Example :
int add(int a , int b);
Add to Two Number using function
#include <iostream> #include <conio.h> using namespace std; int add(int x, int y);//function declaration or prototype int main() { int num1; //variable for store first numbers int num2; //variable for store second numbers int sum; //variable for store result of product //read numbers cout << "Enter the first number" << endl; cin>>num1; //stored first number- get input from user cout << "Enter the second number" << endl; cin>>num2; //stored second number- get input from user sum=add(num1, num2);//calling function and stored returning the result by function; //print sum of numbers cout<<"Addition of two Number is : "<<sum<<endl; getch(); return 0; } //function definition int add(int x, int y) { return (x+y); //return the product result to main }
Output:
Enter the first number 10 Enter the first number 20 Addition of two Number is : 30
Function Declarations in c++ in Hindi
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 <iostream> using namespace std; /* 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); cout<<"Greater value is : "<<greater<<endl; 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 <iostream> using namespace std; // 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); cout<<"Max Value is "<<m<<endl; return 0; }
Output :
Max Value is 20
Upper Diye gye output dekh kar aap program ko samanjh sakte hai|
Category of functions in c++ in Hindi
C++ Programming Me Functions ko 4 category me bata gya hai |
- Function with Arguments and Return value
- Function with No Arguments and No Return Value
- Function with Arguments and No Return Value
- Function with No Arguments and Return Value
Function 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++ in Hindi
- Call by Value
- Call By Reference
1. 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 <iostream> using namespace std; void fun(int x) { x = 50; } int main(void) { int x = 20; fun(x); cout<<"x = "<<x; return 0; }
Output:
x = 20
Upper Diye gye output dekh kar aap call by value program ko samanjh sakte hai|
2. Call By Reference :- Call By Reference Matlab ye keval address ko hold karta hai |
Example :
#include <iostream> using namespace std; void fun(int *ptr) { *ptr = 30; } int main() { int x = 20; fun(&x); cout<<"x = "<<x; return 0; }
Output:
x = 30
Functions in C++ with examples in Hindi
Also Read This Post :
Dosto mujhe ummed hai ki aap functions in cpp in hindi 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 |