हिंदी माध्यम नोट्स
Categories: C Language in hindi
User Define Function : Calls or Declaration in hindi यूजर डिफाइन फंक्शन कॉल या डिक्लेरेशन हिंदी में
यूजर डिफाइन फंक्शन कॉल या डिक्लेरेशन हिंदी में User Define Function : Calls or Declaration in hindi in c language :-
इससे पहले के article मे , हमने function difination को स्टडी किया | इस article मे ,function calling और declaration को स्टडी करगे |
Function Call:
किसी function को उसके नाम से easily call कर सकते है |function का parameter की लिस्ट जिसे actual parameter कहते है |इसका syntax होता है |
Function Name (Actual parameter);
जब function call satement execute होता तब कोम्प्लिएर का control उस function के defination पर चला जाता है |यह पर function defination मे स्थित statement को line by line execute करता है और return statement से ओउपुत को main function मे return कर देता है |
उदाहरण के लिए :
#include<conio.h>
#include<stdio.h>
int add (int ,int )
void main()
{
int a,b ;
printf(“Enter your data”);
scanf(“%d $%d”,&a,&b);
c=add ( a , b );
printf(“Sum is %d”,c);
getch();
}
int add(int e,int f)
{
int sum;
int sum;
sum=e+f;
return sum;
}
इसमें add एक function है जिसमे actual parameter a और b की value , function defination satement मे formal value e और f मे pass होगी |
आउटपुट होगा :
Enter your data 12 23
Sum is 35
अलग अलग function call statement निम्न है :-
c=add(12,23);
c=add(12,b);
c=add(a,23);
c=add(a+1,12);
c=add(12,add(a,b));
पहले statement मे ,actual parameter मे दो constants को pass किया गया है |
दुसरे statement और तीसरे statement मे ,actual parameter मे एक variable और एक constant को pass किया गया है |
statement-4 मे , actual parameter मे एक expression और variable को pass किया गया है |
statement-5 मे , खुद function और variable को pass किया गया है |
अगर किसी function मे , कोई भी value pass नहीं करने तब function call का syntax है :-
c= function name ( );
इसमें actual parameter मे कोई भी variable ,constant,function और expression नहीं होता है |जैसा:
#include<conio.h>
#include<stdio.h>
int add (int ,int );
void line();
void main( )
{
int a,b ;
printf(“Enter your data”);
scanf(“%d $%d”,&a,&b);
c=add ( a , b );
line();
printf(“Sum is %d.”,c);
line();
getch();
}
int add(int e,int f)
{
int sum;
int sum;
sum=e+f;
return sum;
}
void line()
{
for(i=0;i<=20;i++)
{
printf(“*”);
printf(“*”);
}
}
}
इस प्रोग्राम मे , दो user define function है |add() और line() function : add() function मे parameter pass हो रहे है लेकिन line() function मे कोई भी parameter pass नहीं हो रहा है |
आउटपुट होगा :
Enter your data 12 23
*********************
Sum is 35.
*********************
Function Declaration:
किसी function को प्रोग्रम मे use करने से पहले ,Function को प्रोग्राम के header space मे Declare किया जाता है | इस syntax के 4 parts होते है |इसका syntax है :-
function type function name (parameter list) ;
इसमें
function type: ये specify करता है की function से किस तरह का आउटपुट return होता है |
function name : ये function का नाम होता है |
Parameter list : ये फ़ुन्क्तीओन मे pass होने वाले parameter की लिस्ट होती है |
किसी function को declare करने की जगह से उस function का scope का पता चलता है :-
Local Scope :
अगर किसी function को function definition मे declare किया जाता है तब इसका scope local होता है |इसे केवल उस function की body मे use किया जा सकता है |उदहारण के लिए :
#include<conio.h>
#include<stdio.h>
int add (int ,int );
void main( )
{
int a,b ;
printf(“Enter your data”);
scanf(“%d $%d”,&a,&b);
add ( a , b );
getch();
}
int add(int e,int f)
{
void line();
int sum;
int sum;
sum=e+f;
line();
prinf(“Sum is ;%d”,sum)
line();
}
void line()
{
for(i=0;i<=20;i++)
{
printf(“*”);
printf(“*”);
}
}
}
इस उदाहरण मे , line () function को main() function use नहीं कर कर सकते है क्योकि इसका declartion add() function मे किया गया है |ये local function की तरह कार्य करेगा|
आउटपुट होगा :
Enter your data 12 23
*********************
Sum is 35.
*********************
Global Scope :
जब किसी function को main() function उपर declare किया जाता है |तब उस function का PROTOTYPE / SCOPE global होगा |इसे main function और बाकि के user define function मे use किया जा सकता है |सभी function को main() function से पहले ही declare किया जाना चाहिए |
उदहारण के लिए:
#include<conio.h>
#include<stdio.h>
int add (int ,int );
int mul(int,int);
void line();
void main()
{
int a,b ;
printf(“Enter your data”);
scanf(“%d $%d”,&a,&b);
c=add ( a , b );
d=mul (a , b );
printf(“Sum is %d.”,c);
line();
printf(“Multiplication is %d.”,d);
getch();
}
int add(int e,int f)
{
int sum;
int sum;
sum=e+f;
return sum;
}
int mul (int g,int h)
{
int mul;
int mul;
mul=g*h;
return mul;
}
void line()
{
for(i=0;i<=20;i++)
{
printf(“*”);
printf(“*”);
}
}
}
इस उदहारण मे तीन User define functions line(),add() और mul() है |
आउटपुट होगा :
Enter your data 12 23
Sum is 35.
*********************
Multiplication is 276.
Recent Posts
Question Tag Definition in english with examples upsc ssc ias state pcs exames important topic
Question Tag Definition • A question tag is a small question at the end of a…
2 weeks ago
Translation in english grammer in hindi examples Step of Translation (अनुवाद के चरण)
Translation 1. Step of Translation (अनुवाद के चरण) • मूल वाक्य का पता करना और उसकी…
2 weeks ago
Report Writing examples in english grammer How to Write Reports explain Exercise
Report Writing • How to Write Reports • Just as no definite rules can be laid down…
2 weeks ago
Letter writing ,types and their examples in english grammer upsc state pcs class 12 10th
Letter writing • Introduction • Letter writing is an intricate task as it demands meticulous attention, still…
2 weeks ago
विश्व के महाद्वीप की भौगोलिक विशेषताएँ continents of the world and their countries in hindi features
continents of the world and their countries in hindi features विश्व के महाद्वीप की भौगोलिक…
2 weeks ago
भारत के वन्य जीव राष्ट्रीय उद्यान list in hin hindi IAS UPSC
भारत के वन्य जीव भारत में जलवायु की दृष्टि से काफी विविधता पाई जाती है,…
2 weeks ago