I was simply explaining to you that all functions return no matter what. Now for the sake of pure C you only use a return upon returning from a function that returns a value. All functions do return - but void functions have an intrinsic return that the compiler puts in for you - functions that return a value have an intrinsic return - but the compiler does not know what to return so you must tell it.
A good programming habit to get into is one entry point and one exit point per function and - one function does one thing. Using a return to leave a function mid-way is not a good practice. The only reason I can see to use a return midway through a function is in a recursive function.
Exiting out of a function mid-way makes your code very hard to follow and also violates several rules - although it can be done.
The proper way to use a return statement is this:
Code:
int Add(int a,int b)
{
return (a+b);
}
You can also return pointers to objects and classes. You can also return arrays but I don't recommend doing it. If you need to fill an array do it like this or simply return a pointer to the array. You can return an array via the stack but again I don't recommend doing it although it is possible.
Code:
//Adds array1 and array2 and puts result in arraytoset
void SetArray(int array1[2][2], int array2[2][2],int arraytoset[2][2])
{
for (int ii=0;ii<2;i++)
{
for (int j=0;j<2;j++)
{
arraytoset[ii][j]+=array1[ii][j]+array2[ii][j];
}
}
}
Have to use ii or board will interpret it as italics not array.
When a C function returns, that function is responsible for cleaning up the stack. I cannot explain to you the entire stack process as it would only serve to confuse you at this juncture.
NOTE: Is there a way to turn off the bold italic and other things inside of a code section. Look at the above example. The board sees my 'i' as an italics command, not as part of a C array. So it puts everything in italics after that. Then when I want to use italics again....it fails because it's looking for a '/i'.
???