424,303 Members | 1,356 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,303 IT Pros & Developers. It's quick & easy.

if we write return 0; at the end of the function then it means that the programme was

P: 1
if we write return 0; at the end of the function then it means that the programme was successfully executed. but how could i know that the programme has been successfully executed? because i haven't run the programme yet.so before running the programme i ami declaring that the programme was successfully executed. it becomes funny to me.so please clarify the topic
Jan 2 '19 #1
Share this Question
Share on Google+
1 Reply


Expert 100+
P: 2,389
Your program can check for certain specific error conditions (invalid input value, file not found, unable to allocate memory, etc.). You have the option to inform the caller of these detected error conditions via the return code, signal(), errno, assert(), or whatever other method you choose. it is worthwhile to expend some effort designing a consistent error handling methodology.

The main() function is a special case. The C Standard says that the runtime system will translate return value 0 or EXIT_SUCCESS into an implementation-specific code that is interpreted as “success” by the host operating system. Likewise, return code EXIT_FAILURE will be converted to an implementation-specific code that is interpreted as “failure” by the host operating system. There is no guarantee how the host operating system will interpret any other return codes from main()

There is no rule for return codes from non-main functions. It is not uncommon for zero versus nonzero return code to distinguish success and failure, but this is more style than rule.
Jan 3 '19 #2

Post your reply

Sign in to post your reply or Sign up for a free account.