Friday, May 18, 2012

Why main does not return 0 here?


I was just reading



ISO/IEC 9899:201x Committee Draft — April 12, 2011



in which i found under 5.1.2.2.3 Program termination




..reaching the } that terminates the main function returns a value of 0.



it means if you don't specify any return statement in main() , and if the program runs successfully, then at the closing brace } of main will return 0.



But in the following code i don't specify any return statement, yet it does not return 0




#include<stdio.h>
int sum(int a,int b)
{
return (a + b);
}

int main()
{
int a=10;
int b=5;
int ans;
ans=sum(a,b);
printf("sum is %d",ans);
}



compile




gcc test.c
./a.out
sum is 15
echo $?
9 // here it should be 0 but it shows 9 why?


Source: Tips4all

No comments:

Post a Comment