why don't we put return1; or return2; or any other integer value in return statement why we always put return0; at the end | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 11

why don't we put return1; or return2; or any other integer value in return statement why we always put return0; at the end

25th Jan 2017, 5:37 PM
sonali
sonali - avatar
14 Antworten
+ 7
Since your code isn't returning anything therefore we write return 0 statement; as the datatype of main is integer so you can return any integer number(or nothing at all, just don't write the return thing). It's just like "why we use void?"=because we are returning nothing at all. Simple. HappyCoding;
26th Jan 2017, 12:32 PM
Navneet Sharma
Navneet Sharma - avatar
+ 5
what if i put return -1;
25th Jan 2017, 5:50 PM
sonali
sonali - avatar
+ 5
@chetan to be very honest ... i just guess the answer its 3
9th Feb 2017, 2:28 PM
sonali
sonali - avatar
+ 3
You don't have to return 0, you can return anything you want. In main return 0 is often used for successful execution of the code and other return values for different errors or problems that forced the program to manually terminate.
25th Jan 2017, 5:50 PM
Robobrine
Robobrine - avatar
+ 3
it depends on you to use 1 ,2,3,-1 anything... and also it depends on the conditions..
19th Feb 2017, 2:20 AM
Pranjal Singh
Pranjal Singh - avatar
+ 2
you can return anything as you wish
4th Feb 2017, 8:43 AM
Soubhik Samadder
Soubhik Samadder - avatar
+ 2
it depends on the data type in function declaration if it is 'void' then we write return '0'
5th Feb 2017, 6:29 PM
Rohit Thakur
+ 2
@sona thanks for liking my answer..and also for my code..alphabet pyramid
19th Feb 2017, 12:58 PM
Pranjal Singh
Pranjal Singh - avatar
+ 1
Integers normally range from -2147483648 to 2147483647, so as long as you stay within those bounds it will work.
25th Jan 2017, 5:53 PM
Robobrine
Robobrine - avatar
+ 1
This question is commonly asked. Here is a short answer for you. 1- Functions can return values. e.g. y = f(x). The value of x is processed by function f and the return value is stored in variable y 2- Main is a function, but what happens to the returned value? There are multilple ways to know the returned value. But the important thing to know is that, by convention, we interpet the value 0 to mean that no error occurred.
25th Jan 2017, 6:45 PM
Chadi Trad
Chadi Trad - avatar
+ 1
code and let us know what you get.
25th Jan 2017, 7:17 PM
shashi prakash
shashi prakash - avatar
0
gangs zygote a xhzn substance dismay ducts xyx5x6zh
27th Jan 2017, 4:24 PM
PARTHA MANDAL
PARTHA MANDAL - avatar
- 7
actually @sonali Sharma u ques is very good and here is ur ans we use return1 or return 0 because there are only two possibilities whether it will return a value or not when it doesn't return value we use return 0 and when it does we write just return or return 1. and as we know main function does not return value but when we use INT main then it should return a value due to function prototype so we use return 0
26th Jan 2017, 12:36 PM
Prince Kumar
- 7
and @sonali Sharma if u want more query clarification u can contact me on Facebook my id is rihaan@rediffmail.com okk fine bye
26th Jan 2017, 12:39 PM
Prince Kumar