+ 8

Why we use return=0?

14th Nov 2016, 7:52 AM
Tayyaba Irshad
Tayyaba Irshad - avatar
17 Answers
+ 12
this method to help you track your errors for example: #include <iostream.h> using namespace std; int main() { int temp=0; cout << "Enter a number bigger then 1: " << endl; cin >> temp; if(temp <1) return -1; cout << "The number is: " << temp << endl; return 0; } if you input a number smaller then 1 then porgram stop and in the output window of your IDE will print something like: threat 0xffffffff exit with code -1; in the end it's an old way to track errors but it very useful in more complicated codes. i use it personally ;). hope that help
14th Nov 2016, 9:08 AM
George Rabbat
George Rabbat - avatar
+ 3
It is only used when you declare your main function as int like int main() { //here is your code return 0; } Try void instead of int you don't need to use return 0. But you have to use getch(); else your program console will close it automatically(works only in pervious version of c compiler). Return 0 also used to hold program console to stop automatically closing. When you enter some keyword it close its console.
14th Nov 2016, 8:01 AM
Aditya kumar pandey
Aditya kumar pandey - avatar
+ 2
Becuse you let function main with int return, so the function shold return value. If you want not, let function main with void return. ex: void main (){}
10th Feb 2017, 4:19 AM
Abdulhameed Alhababi
Abdulhameed Alhababi - avatar
+ 1
we use return 0 because the main function is an int function and it returns any integer, for no specific return value, we write as code "return 0".
15th Nov 2016, 6:53 PM
Suman Anand
Suman Anand - avatar
+ 1
this is long rooted and comes stems from the UNIX operating system, where the adagio is "no news is good news". A return code of 0 means all-OK, thumbs up, in the clear... you get what I mean.
22nd Nov 2016, 10:35 AM
John van der Vuurst
John van der Vuurst - avatar
0
Return statement is used as in c++ main is rwturning int as int main () shows........whereas complier predict return=0 that program has terminated normally whereas if we return non zero integer then compiler predict it as abnormally termination of code!!
14th Nov 2016, 8:05 AM
ROHAN JOSHI
ROHAN JOSHI - avatar
0
Modern compilers will invisibly add the return 0 statement for you if you leave it out, so you don't need to write it unless you have a use for it.
14th Nov 2016, 9:21 AM
Noah Davis
Noah Davis - avatar
0
it is not just a value, return value of main() is a code understood by operating system.0 is for success and nonzero is for failures
15th Nov 2016, 6:05 AM
Cengiz Poyraz
Cengiz Poyraz - avatar
0
this is my understanding, although Im still learning :) we return a value of 0 to indicate that the function executed as expected, without any problems. Any nonzero char will tell the compiler that an error has been encountered during execution. if we use type int for our main function I.e. int main() { ... whatever statements ; return 0; } this indicates that our main function is of type int, therefore we can only return an int from it. should no return value be specified, then a 'trash' value will be returned that we can usually ignore. return 0 simply ensures that a 0 is returned rather than any other int when the function completes. if you use void (usually it will generate an error), therefore int with return 0 is the standard.
15th Nov 2016, 8:35 AM
Tony Robinson
Tony Robinson - avatar
0
to end your source code
7th Feb 2017, 11:56 AM
mangesh borkar
mangesh borkar - avatar
0
its the end or closure of every program
18th Feb 2017, 4:35 PM
Nakityo Jane Frances
Nakityo Jane Frances - avatar
0
clean compilation
3rd Sep 2017, 6:08 PM
Anurag
- 1
so if i use void instead of int i don't have to use return
14th Nov 2016, 8:04 AM
Tayyaba Irshad
Tayyaba Irshad - avatar
- 1
if anyone use another one try bcz zro is only use fr return if other one try it and told me👌
16th Nov 2016, 3:12 PM
Anand Yadav Anand Yadav
Anand Yadav Anand Yadav - avatar
- 1
To sum it up, if you declare your main as int main () then main acts like a function and requires a return value. Most people use 0 as the return value because typically that denotes successful completion to whatever is calling the program. If you declare your main as void main () then main is a sub routine and not a function, and as such does not have a return statement.
24th Nov 2016, 6:00 PM
David-Hesh Hochhauser
David-Hesh Hochhauser - avatar
- 2
we use it as 0 has no value!
15th Nov 2016, 5:47 PM
Thejaswin Ganesh
Thejaswin Ganesh - avatar
- 2
return 0 simplify no errors
3rd Dec 2016, 2:47 PM
Hemanta Garai
Hemanta Garai - avatar