Function with more than one return
इससे पहले हमने पड़ा था की return statement से किसी एक value को return करा सकता है |लेकिन जब programmer को more than two data values को return करना होता है तब इस function को use कर सकते है |
इसमें function को call करते समय actual parameter मे किसी आउटपुट variables के अद्द्द्रेस को formal parameter मे pass करते है | इन address पर data values सेव हो जाती है जो main() function मे use कर सकते है |
उदहारण के लिए :
#include<stdio.h>
#include<conio.h.
int calculation(int a,int b,int*c,int*d)
void main()
{
int a =23,b=12,c,d;
calculation(a,b,&c,&d);
printf(“Addition of Numbers=%d\n”,c);
printf(“Multiplication of Numbers=%d”,d);
getch();
}
int(int e,intf,int*sum,int*mul)
{
sum=e+f;
mul=e*f;
}
int*sum एक pointer है जो की variable c के address को होल्ड कर रहा है |
sum=e+f; statement मे e+f; का जो आउटपुट होगा वो sum address पर store हो जायेगा inshort c के address पर store हो जायेगा |ये पूरा process mul और variable d के साथ भी होगा |
calling function calculation(a,b,&c,&d); मे variable c और d के address PASSED होगा |
आउटपुट होगा :
Addition of Numbers=35
Multiplication of Numbers=276
Nesting of function :
C language function of function को allow करता है जैसे main() function , function 1() को call करता है function 1() ,function 2() को call करता ही function 3() ,function 4() को call करता है |C language मे function की nesting की कोई limit नहीं होती है |
उदहारण के लिए:
#include<stdio.h>
#include<conio.h.
int calculation(int a,int b)
int mul( int, int );
void main()
{
int a =23,b=12,c,d;
c=calculation(a,b);
printf(“Output of Numbers=%d\n”,c);
getch();
}
int(int e,int f )
{
int sum ;
sum=e+mul(e,f);
return sum;
}
int mul( int i,int j )
{
int g;
g=i*j;
}
इस प्रोग्राम मे तीन function है main() ,add() और mul() |main() function , add() को call करता है और add() function , mul() को call करता है |जब sum =e+mul(e,f) execute होता है तब mul() function की return value का addition ,e होता है |
आउटपुट होगा :
Output of Numbers=299]
Array Passing in function :
int a[5]={12,23,21,45,34};
int max (int a [],int size)
max=a[i];
Maximum number is 45
अगर user define function मे array की value मे कोई change होगा तब वे change main array मे होता है |जब पूरी array as formal arguments pass होती है तब उसके values pass नहीं होती |उन values के address pass होती है |
Two -Dimensional Array :
जब किसी Two -Dimensional Array को function arguments मे pass किया जाता है tab ये syntax को फॉलो करना पड़ता है |
function calling मे, केवल array का नाम से call किया जाता है |
syntax : function name (array _name) ;
function definition मे , array को दो brackets के साथ बताया जाता है और second subscript की value को लिखा जाता है |
syntax : function type function_name (int array_name[ ][size],int row size,int column size);
Function header का syntax one dimension array की तरह होता है |
उदहारण के लिए:
int a[row][colunm]={12,23;
int max (int a [][],row,colunm,b[][],row,colunm)
आउटपुट होगा :
28 47
28 70