lamrinnirmal said:dude KuKlux pm me your email .... i ll host a few ebooks on C on a hosting server where you can download em off........or just search the forum....there are quite a lot of links to ebook sites(all legal!)
about nested functions............hope the below code clears your confusion.
imagine of a traveller moving to the different countries from main and when hes in australia() he doesnt go to anyother place(cause australia() doesnt call any function) and thus to find his way back to main he climbs up the way he came down.........
Code:void india(); void england(); void usa(); void australia(); void main() { printf(" i am in main"); india(); printf("jus got back from india!.......finally here...what a ride"); } void india() { printf("im in india! "); england(); printf("jus got back from england.....!"); return; } void england() { printf("im in england.......the queen aint hot!"); usa(); printf("jus got back from usa"); return; } void usa() { printf("im in usa......so whats so great bout this place?pathetic!"); australia(); printf("got back from australia"); return; } void australia() {printf("lost in the outbacks!.....gotta find myself way back"); return; }
your output would be.....
i am in main
im in india!
im in england.......the queen aint hot!
im in usa......so whats so great bout this place?pathetic!
lost in the outbacks!.....gotta find myself way back
got back from australia( now you are in usa)
jus got back from usa(now in england)
jus got back from england.....!(now in india)
jus got back from india!.......finally here...what a ride(home sweet main.....program ends
aadipa said:lamrinnirmal said:dude KuKlux pm me your email .... i ll host a few ebooks on C on a hosting server where you can download em off........or just search the forum....there are quite a lot of links to ebook sites(all legal!)
about nested functions............hope the below code clears your confusion.
imagine of a traveller moving to the different countries from main and when hes in australia() he doesnt go to anyother place(cause australia() doesnt call any function) and thus to find his way back to main he climbs up the way he came down.........
This is not a nested function. Just a simple function calling other function.
Nested Functions=Functions Within Functions.....They're a bit confusing...
Particularly the ones with many nestings.....
while (TRUE)
{
some code.... ;
for (x=1; x<=20; x++)
{
some code .... ;
}
}
tuxfan said:Ok. So the confusion is cleared about what is nested function. Actually, there is nothing called nested function. There may be nested loop. For example
Code:while (TRUE) { some code.... ; for (x=1; x<=20; x++) { some code .... ; } }
These functions calling another function is pretty simple. Tell us what you don't understand about them.
prasadzmultiplex said:Yeah I pretty much understand what the nesting of loops is all about...
But u ce ethe thing with functions is that they return to where it was called
from after performing the task.That is where I get into a mess....
prasadzmultiplex said:For eg..I call a function at line 6 of my prog....It goes to its definition which i have provided at the end,carrieds out the task & returns back to line 7 and then the prog ontinues....
Huh?? What are you trying to ask? Control is never returned back the statement that defines a function. It is always retuned to the statement that calls it.prasadzmultiplex said:WIth nesting of functions,it becomes complicated.....If suppose there is a function within the definition of the earlier function,where does it go to after it gets executed? Back to the Definition part or the Earlier function called part??
Take a very simple example. You have a function called Add3Numbers(). This is how you call it. Here the function returns a value.prasadzmultiplex said:Also what do u mean when u say " A Function returns with a value"?
Sum1 = Add3Numbers(23,12,34);
Sum2 = Add3Numbers(num1,num2,num3);
int Add3Numbers (int a, int b, int c)
{
int total;
total = a + b + c;
return (total);
}
tuxfan said:Mr. Racist aka Mr. Facist, what are you trying to ask? I didn't understand the first question If its only about odds and evens, why not use a mod operator?
for(i=1,j=0;i<6;i=i+2,j=j+2)
{
scanf("%d",&data);
if(data%2!=0)
a[i]=data;
else
a[j]=data;
}
i=0;
j=1;
while(i<=20&&j<=19)
{
scanf("%d",&data);
if(data%2!=0)
{
a[j]=data;
j=j+2;
}
else
{a[i]=data;
i=i+2;
}
}
prasadzmultiplex said:Now I hate bothering u guys again but I have hit a wall again