c - Return 1 in non main function -
i learning c , have confusion regarding return:
int factorial (int n) { if (n == 1) return 1; else return n * factorial (n -1); }
in above recursive code in last call when n 1, return 1 return integer value 1 or error in execution in main. had confusion because return 1 treated differently in main , in function called main...
will
return 1
return integer value 1 or error in execution in main?
return 1
returns integer value 1
any function declared return int
, even if function happens int main()
.
a non-zero return value main()
interpreted (by execution environment, e.g. shell) indicate error in execution. happens semantic of return value of main()
.
Comments
Post a Comment