I'm reading Programming in C by Brian Kernighnan an Dennis Ritchie in that(pg.25 bottom)
Here the author quotes:
The value that power computes is returned to main by the return statement. Any expression may follow return: return expression ;
But in the code he provided above:
#include <stdio.h>
int power(int m , int n);
main()
{
int i;
for (i = 0; i < 10; ++i)
printf ( " %d \t %d \t %d \n ", i, power( 2 , i), power( -3 , i));
return 0;//no. 1
}
int power(int m , int n)
{
int i, p ;
p = 1;
for (i = 1; i <= n; ++i)
p = p * m;
return p; //no. 2
}
Here I understood why he used 2. return p;
in function power (i.e to get the value of p) but why does he use 1. return 0;
??
I tried removing the line return 0;
And it still worked as I had thought, is there something I'm missing??
[UPDATE]
I'm sorry for not including this before but I already knew this much:
quoted in the book:
You may have noticed that there is a return statement at the end of main. Since main is a function like any other, it may return a value to its caller, which is in effect the environment in which the program was executed. Typi- cally, a return value of zero implies normal termination; non-zero values signal unusual or erroneous termination conditions. In the interests of simplicity, we have omitted return statements from our main functions up to this point, but we will include them hereafter, as a reminder that programs should return status to their environment.
Thanks to @Pascal I was able to understand the difference in both the return p; and return 0; However my intention was never to know what return 0; was but why return was used also to know the difference between both the return statment......