JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now

हिंदी माध्यम नोट्स

Categories: c++ language in hindi

C++ : User Define Function Return Statement in hindi , what is User Define Function Return Statement in c++ language

इससे पहले के article मे function का basic staruture को discuss किया है | अब इस article मे function मे argument को pass करने के तरीके और return statement को discuss करेगे |

Argument

किसी programing language , argument का मतलब उस data से define करता है जिसे function मे pass किया जाता है | अतः argument किसी variable को define करता है जिसे function मे pass किया जाता है | ये main() function से data value को यूजर define function मे pass किया जाता है | निन्म उदाहरन से argument को समजा जा सकता है :-

#include

#include

using namespace std;

// Function prototype (declaration)

int sub(int, int);

int main()

{

int num1, num2, sub;

cout<<“Enters two numbers : “; cin >> num1 >> num2;

// Function call

sub = sub(num1, num2);

cout << “Output : ” << sum; getch(); } // Function definition int sub(int a, int b) { int output; output = a – b; // Return statement return output; } उपर के उदाहरन मे , दो variable num1 और num2 को function sub() मे pass किया जाता है | in variable को function sub () calling statament मे pass किया गया है | call statement मे pass किये गये argument को actual parameter कहते है | function defintion मे variable ‘a’ और ‘b’ मे call statement मे pass variable को initial किया गया है | in variable को user define function मे use किया जाता है | अतः variable ‘a’ और ‘b’ को formal parameter कहते है | इसका आउटपुट होगा : Enters two numbers : 12 2 Output : 10 Argument Pass के rules 1.actual parameter और formal parameter की number सामान होती है | 2.actual parameter और formal parameter के type भी सामान होती है | अतः पहले actual parameter के type , formal parameter से matched होना चाहिए | और second actual parameter का type , फोम्मल parameter से match होता है | 3.किसी function को argument के बिना भी call किया जा सकता है | argument को pass करने का desicion प्रोग्रामर पर होता है | 4.किसी default argument को function call statement मे पस्सेद्क किया जा सकता है | default parameter , वे variable होते है जिसकी value default होती है | 5.function मे अलग अलग type के variable को pass किया जा सकता है | इन rules को समजने के निन्म उदाहरन को consider करेगे : #include

#include

using namespace std;

// Function prototype (declaration)

int mul(int, int);

int main()

{

int num1, num2, m;

cout<<“Enters two numbers : “; cin >> num1 >> num2;

// Function call

m = mul(num1, num2);

cout << “Output : ” << m; getch(); } // Function definition int mul(int a, int b) { int output; output = a * b; // Return statement return output; } इस उदाहरन मे mul() एक user define function है जिससे multiplication task को किया गया है | function call statement mul(num1, num2); मे pass actual parameter की सख्या ‘2’ है और function definition statement मे भी formal parameter की सख्या ‘2’ है | function call statement mul(num1, num2); मे pass actual parameter की type integer है और function definition statement मे भी formal parameter का type भी integer है | इसका आउटपुट होगा : Enters two numbers : 12 2 Output : 24 Return Statement कोई user define function मे केवल एक value को return किया जा सकता है | इस value को call function statement से किसी variable मे assign किया जा सकता है | return statement से user define function के द्वारा value को main() function मे pass की जाती है | लेकिन number ऑफ़ value केवल एक होती है | जब किसी यूजर define function के द्वारा कोई value pass की जाती है तब यूजर define function का type return type के सामान होता है | निन्म उदाहरन मे return statement को use किया गया है : #include

#include

using namespace std;

// Function prototype (declaration)

int div(int, int);

int main()

{

int num1, num2 ,d;

cout<<“Enters two numbers : “; cin >> num1 >> num2;

// Function call

d= div(num1, num2);

cout << “Output : ” << m; getch(); } // Function definition int div(int a, int b) { int output; output = a / b; // Return statement return output; } इस उदहारण मे निन्म पॉइंट्स को consider करना है : div() function से integer value को return किया जाता है इसलिए user define function div() का type ‘int’ है | इसके अलावा function द्वारा integer value को return किया जाता है इसलिए main() function जिस भी variable मे value को assign किया जाता है उसका type भी integer होना चाहिए | इस उदहारण मे return output; return statement है | इस उदहारण मे आउटपुट की value को main() function मे return किया जाता है| main() function मे variable आउटपुट की value variable div मे assign किया जाता है | इसका आउटपुट होगा : Enters two numbers : 12 2 Output : 6 किसी यूजर define function मे return statement होना जरुरी नहीं है | ये प्रोग्रामर पर depend करता है | अगर user define function से कोई भी value return नहीं होती है तब user define function का type void होता है | इसका उदाहरन निन्म है : #include

#include

using namespace std;

// Function prototype (declaration)

void add(int, int);

int main()

{

int n1, n2 ,sum;

cout<<“Enters value1 : “; cin >> n1;

cout<<“Enters value12 : “; cin >> n2;

// Function call

add(n1, n2);

getch();

}

// Function definition

void add(int a, int b)

{

int output;

output = a + b;

cout<<“Output : “<<output; }=”” इस=”” उदाहरन=”” मे=”” user=”” define=”” function=”” से=”” कोई=”” भी=”” value=”” return=”” नहीं=”” हो=”” रही=”” है=”” इसलिए=”” का=”” type=”” void=”” |=”” और=”” main=”” call=”” को=”” डायरेक्ट=”” ही=”” किया=”” article=”” ,=”” argument=”” pass=”” statement=”” discuss=”” अब=”” आगे=”” के=”” करेगे=”” <=”” p=””></output;>

Sbistudy

Recent Posts

मालकाना का युद्ध malkhana ka yudh kab hua tha in hindi

malkhana ka yudh kab hua tha in hindi मालकाना का युद्ध ? मालकाना के युद्ध…

1 month ago

कान्हड़देव तथा अलाउद्दीन खिलजी के संबंधों पर प्रकाश डालिए

राणा रतन सिंह चित्तौड़ ( 1302 ई. - 1303 ) राजस्थान के इतिहास में गुहिलवंशी…

1 month ago

हम्मीर देव चौहान का इतिहास क्या है ? hammir dev chauhan history in hindi explained

hammir dev chauhan history in hindi explained हम्मीर देव चौहान का इतिहास क्या है ?…

1 month ago

तराइन का प्रथम युद्ध कब और किसके बीच हुआ द्वितीय युद्ध Tarain battle in hindi first and second

Tarain battle in hindi first and second तराइन का प्रथम युद्ध कब और किसके बीच…

1 month ago

चौहानों की उत्पत्ति कैसे हुई थी ? chahamana dynasty ki utpatti kahan se hui in hindi

chahamana dynasty ki utpatti kahan se hui in hindi चौहानों की उत्पत्ति कैसे हुई थी…

2 months ago

भारत पर पहला तुर्क आक्रमण किसने किया कब हुआ first turk invaders who attacked india in hindi

first turk invaders who attacked india in hindi भारत पर पहला तुर्क आक्रमण किसने किया…

2 months ago
All Rights ReservedView Non-AMP Version
X

Headline

You can control the ways in which we improve and personalize your experience. Please choose whether you wish to allow the following:

Privacy Settings
JOIN us on
WhatsApp Group Join Now
Telegram Join Join Now