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 :

  1. The return value of main function is always a positive Value.
  2. Inside C Program, Function is nothing but set of instructions combined together in a single block.
  3. Function Block may have certain starting address.
  4. 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

C return value of main function

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.