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

सती रासो किसकी रचना है , sati raso ke rachnakar kaun hai in hindi , सती रासो के लेखक कौन है

सती रासो के लेखक कौन है सती रासो किसकी रचना है , sati raso ke…

10 hours ago

मारवाड़ रा परगना री विगत किसकी रचना है , marwar ra pargana ri vigat ke lekhak kaun the

marwar ra pargana ri vigat ke lekhak kaun the मारवाड़ रा परगना री विगत किसकी…

10 hours ago

राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए sources of rajasthan history in hindi

sources of rajasthan history in hindi राजस्थान के इतिहास के पुरातात्विक स्रोतों की विवेचना कीजिए…

2 days ago

गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है ? gurjaratra pradesh in rajasthan in hindi

gurjaratra pradesh in rajasthan in hindi गुर्जरात्रा प्रदेश राजस्थान कौनसा है , किसे कहते है…

2 days ago

Weston Standard Cell in hindi वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन

वेस्टन मानक सेल क्या है इससे सेल विभव (वि.वा.बल) का मापन Weston Standard Cell in…

3 months ago

polity notes pdf in hindi for upsc prelims and mains exam , SSC , RAS political science hindi medium handwritten

get all types and chapters polity notes pdf in hindi for upsc , SSC ,…

3 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