+ 1

What is the use of return 0 I can't understand by this app, please tell me in detail

use of return 0

28th Oct 2016, 3:59 AM
Akshay Asati
Akshay Asati - avatar
5 ответов
+ 6
When you make your main function of "int" type(You can also have a "void" type return), it must return some data of int type back. If we don't require any value to be returned by the function, we must use 'void' as the return type of function. void means "nothing or no-value" Hence ,when using int type we have to return an integer value. Technically you could return any Integer value. But it is standard practice of returning 0 which generally tells the compiler that the program ran successfully.
28th Oct 2016, 7:50 AM
Anbu Coder
Anbu Coder - avatar
+ 1
return 0; used in finishing the code . you code won't execute without it .
28th Oct 2016, 4:40 AM
wasiq ali siddiqui
0
return 0; is used as a message for the user itself and not the compiler to tell that program has ended successfully......... It's not compulsory that it only has to return zero but is on to you what you want to be returned as a success sign..... You can also type in return 1; if it seems to you that you want to use 1 as a success signal rather than 0........
28th Oct 2016, 9:46 AM
Jatin
0
@Jatin It depends on OS. While Windows does not expect a return value, Unix based operating systems do require a return value. 0 signifies successful running and any non zero value means there were errors. Hence we generally return 0.Hence there are conventions on the value returned. Although I already mentioned that you could return any integer value on OS like Windows as it wouldn't make a difference at a non-technical level.
28th Oct 2016, 10:57 AM
Anbu Coder
Anbu Coder - avatar
0
int main() function is a integer type function and it must return a value. like other integer functions like this example... int sum(int a, int b) { return a+b;} this function will return(or put at place of it) the value of a+b. for eg. c=sum(5,6); is equivalent to c=11; as sum function puts the value of a+b at its place. now if you declare a int main() this function should return a value. as we are not going to call this function so the return statement is useless but it should be there.
28th Oct 2016, 12:48 PM
Rohit Kaushal
Rohit Kaushal - avatar