C return value of main function
In this example we are going to see, what is return value of main function.
Return value of main function
#include<stdio.h> int main() { int c = 5; printf("%d", main || c); return(0); }
Output :
1
Explanation :
- The return value of main function is always a positive Value.
- Inside C Program, Function is nothing but set of instructions combined together in a single block.
- Function Block may have certain starting address.
- This Address gets printed when we try to print function name inside printf statement.
When we try below statement then -
printf("%d", main);
then each time we get different output. While writing this article value printed on the screen was 657
OR Operator with main
In the above example we have OR’ing of two positive numbers so we will get 1
int c = 5; printf("%d", main || c);
Return value of main function is positive non-zero number. c is also non-zero number.
So ORing of two non zero numbers is always TRUE
i.e 1 in C Programming.
Re-commanded Articles :
While going through the stackoverflow, I found good discussion on the similar topic. Topic contain the discussion about return value of main function.