Why return 0 in c




















In every C program you have to use return return 0; or return -1; , or whatever The return value is the exit code of your program, the shell or any other application that ran it can read and use it. The 0 exit code is a widely accepted convention for ' OK the program execution was successfull '.

Posted 5-Dec pm CPallini. Sergey Alexandrovich Kryukov Apr am. Afzaal Ahmad Zeeshan Aug am. CPallini Aug pm. It is a rather old post. Thank you very much. The return value of the main function is considered the "Exit Status" of the application. In stdlib. Posted 6-Dec am Captain Price. Posted 5-Dec pm Optimistic The return value can be used outside the program by the caller program, script or command.

Posted Aug am armagedescu. A return statement ends the execution of a function, and returns control to the calling function.

Execution resumes in the calling function at the point immediately following the call. A return statement can return a value to the calling function. For more information, see Return type. The value of expression , if present, is returned to the calling function. If expression is omitted, the return value of the function is undefined. The expression, if present, is evaluated and then converted to the type returned by the function. When a return statement contains an expression in functions that have a void return type, the compiler generates a warning, and the expression isn't evaluated.

If no return statement appears in a function definition, control automatically returns to the calling function after the last statement of the called function is executed. In this case, the return value of the called function is undefined. If the function has a return type other than void , it's a serious bug, and the compiler prints a warning diagnostic message. If the function has a void return type, this behavior is okay, but may be considered poor style.

Marco A. Community Bot 1 1 1 silver badge. Sunil Kumar Sunil Kumar 4, 4 4 gold badges 29 29 silver badges 32 32 bronze badges.

If you use void main it will return 0. Here is an example for DOS: rem test. The operation of your program is not affected of course. Devolus Devolus The return value has nothing to do with your Output value. That is, even if your output is 10 , you return 0. Every command returns an exit status sometimes referred to as a return status or exit code. A successful command returns a 0 , while an unsuccessful one returns a non-zero value that usually can be interpreted as an error code.

Well-behaved UNIX commands, programs, and utilities return a 0 exit code upon successful completion, though there are some exceptions. Parag Gangil Parag Gangil 1, 2 2 gold badges 10 10 silver badges 25 25 bronze badges. Njol Njol 3, 15 15 silver badges 31 31 bronze badges. Penjor Tshering Answers From the context: return 0 - As mentioned earlier, the function main returns an integer value int main , therefore here we are returning 0.

It's Simple and Conceptual. Get Python course for Days Hours Min Sec. Pro Course Features. Simple Videos.



0コメント

  • 1000 / 1000