हिंदी माध्यम नोट्स
Categories: c++ language in hindi
C++ : Library Function in programming language in hindi ,what is Library Function in c++ language
what is Library Function in c++ language , C++ : Library Function in programming language in hindi :-
Function किसी प्रोग्राम का छोटा part होता है जिसे किसी specific task के लिए बनाया जाता है| C++ मे function का विशेष महत्व होता है | क्योकि Oops मे function को विशेष महत्व होता है |इस article मे function के basic को discuss करेगे और आगे function heading के article मे function के advance ascepts को discuss करेगे |
function दो प्रकार के होते है
(i) With Return value
(ii) Without Return Value
Function को आप खुद बना सकता है और इसे किसी C++ library मे भी विशेष functions को देखा सकते है |
Function with Return value
इस category मे एसे function आते है जिसमे किसी output के लिए एक value generate होती है जिसे किसी दुसरे variable मे assign कर सकते है | उदहारण के लिए
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
int n,a;
cout<< “Enter Number”<<endl;
cin>>n;
a=sqrt(n);
cout<<“Square Root : “<<a<<endl;
getch();
}
इस प्रोग्राम मे , sqrt() एक libarary function है जो की किसी number के square root को calculate किया जाता है | इस प्रोग्राम मे , यूजर द्वारा input किया गया number को sqrt() को pass किया जाता है |इस number का square root calculate किया जाता है |
इस प्रोग्राम मे , a=sqrt(n); statement को function call कहते है | जो की sqrt() function को call करता है |इस प्रोग्राम मे ‘n’ एक argument है जो की function मे पास्ड किये जाने वाले information है जिस पर operation होता है| इस function से square root को calculate किया जाता है और इसके आउटपुट को variable ‘a’ मे assign कर दिया जाता है |
Function Prototype
function prototype function का declaration होता है | ये function मे pass होने वाले arguments और function का नाम को declare करता है |
उदाहरण :
#include<iostream.h>
#include<conio.h>
int squareroot( int );
void main()
{
int n,a;
cout<< “Enter Number”<<endl;
cin>>n;
a= squareroot (n);
cout<<“Square Root : “<<a<<endl;
getch();
}
int squareroot( int num )
{
return(num*num);
}
यहा पर int squareroot( int ); function declartion है जिसमे
int : Return type को declare करता है |
squareroot : function का नाम है |
(int) : ये function मे pass होने वाले arguments के type को declare करता है |
function declaration को हमशा semicolon से terminate करता है |जब किसी library function को use किया जाता है तब c language मे real number के लिए integer को use किया जाता है |लेकिन c++ मे इस argument के लिए double type को use किया जाता है | जैसे उदाहरण 1 मे sqrt() का function declartion होता है :
double sqrt(double);
इस function declaration को header file मे declare किया जाता है |सभी function का header file मे prototype होते है इसलिए function description को manual और online check किया जाता है |अतः sqrt() function का prototype math.h और cmath मे declare होता है |
function declaration और function definition प्रोग्रामर हमेशा confusion होता है|लेकिन दोनों ही syntax अलग होते है |
function prototype को function मे pass information और function द्वारा return किया जाने वाले information को define करता है |
function definition से function को प्रोग्राम मे add किया जाता है |
Function with multiple arguments
function मे एक या एक से अधिक arguments को pass किया जा सकता है उदहारण के लिए
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
int n,b,a;
cout<< “Enter Base”<<endl;
cin>>n;
cout<< “Enter Power”<<endl;
cin>>n
a=pow(b,n);
cout<<“Square Root : “<<a<<endl;
getch();
}
इस उदाहरण मे pow() function मे दो arguments को pass किया जाता है | “b” :base ,”n” : power है अतः pow() function मे base के power को calculate किया जाता है |
इसके अलावा कुछ function एसे भी होते है जिसमे कोई argument pass नहीं होता है |उदाहरण के लिए rand() function मे कोई argument pass नहीं होता है |इसका prototype होता है :
int rand( void );
यहा पर void , no argument को declare करता है | लेकिन अगर प्रोग्रामर void को omit कर देता है () को blank छोड़ देता है तब भी prototype उचित होता है |
इसके अलावा एसे function होते है जिसमे कोई return value नहीं होती है |अगर प्रोग्रामर कोई print() function को produce करता है तब इस function से कोई value return नहीं होती है | केवल data को screen पर print करने के लिए भेजा जाता है | उदाहरण के लिए
#include<iostream.h>
#include<conio.h>
void main()
{
int r;
cout<<“Enter money in Indian currency :” << endl;
cin>>r;
dollar(r);
getch();
}
यहा पर dollar function कोई भी value को return नहीं कर रहा है |ये function यूजर द्वारा input की जाने वाली Indian currency को dollar मे convert करके ,screen पर print कर देता है |
User Define Function
User define function एसे function होते है जिसे यूजर द्वारा define किया जाता है | इसके तीन मुख्य भाग होते है :-
(i)function declaration
(ii)function call
(iii)function definition
उदाहरन के लिए
#include<iostream.h>
#include<conio.h>
int squareroot( int ); // function declaration
void main()
{
int n,a;
cout<< “Enter Number”<<endl;
cin>>n;
a= squareroot (n); // function calling
cout<<“Square Root : “<<a<<endl;
getch();
}
int squareroot( int num ) // function definition
{
return(num*num);
}
user define function को C++ : User Define Function मे सार से discuss करेगे |
Recent Posts
मालकाना का युद्ध malkhana ka yudh kab hua tha in hindi
malkhana ka yudh kab hua tha in hindi मालकाना का युद्ध ? मालकाना के युद्ध…
4 weeks ago
कान्हड़देव तथा अलाउद्दीन खिलजी के संबंधों पर प्रकाश डालिए
राणा रतन सिंह चित्तौड़ ( 1302 ई. - 1303 ) राजस्थान के इतिहास में गुहिलवंशी…
4 weeks ago
हम्मीर देव चौहान का इतिहास क्या है ? hammir dev chauhan history in hindi explained
hammir dev chauhan history in hindi explained हम्मीर देव चौहान का इतिहास क्या है ?…
4 weeks ago
तराइन का प्रथम युद्ध कब और किसके बीच हुआ द्वितीय युद्ध Tarain battle in hindi first and second
Tarain battle in hindi first and second तराइन का प्रथम युद्ध कब और किसके बीच…
4 weeks ago
चौहानों की उत्पत्ति कैसे हुई थी ? chahamana dynasty ki utpatti kahan se hui in hindi
chahamana dynasty ki utpatti kahan se hui in hindi चौहानों की उत्पत्ति कैसे हुई थी…
1 month ago
भारत पर पहला तुर्क आक्रमण किसने किया कब हुआ first turk invaders who attacked india in hindi
first turk invaders who attacked india in hindi भारत पर पहला तुर्क आक्रमण किसने किया…
1 month ago