Why to write "return 0 ;" when function is (int main) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why to write "return 0 ;" when function is (int main)

21st Jul 2017, 8:42 AM
Deep Jani
Deep Jani - avatar
12 Answers
+ 2
deep jani, if you are a programmer then you should have to know that every function has its return type like int,float or void etc.. when main method is called with integer return type then will have to write return 0; because 0 is a integer and it return 0.
21st Jul 2017, 8:59 AM
Alok Singh
Alok Singh - avatar
+ 1
if its a char then can we write return a;
21st Jul 2017, 9:01 AM
‎ ‏‏‎Anonymous Guy
+ 1
main method is called either int main() or void main() and mostly void main is not used in c++ .
21st Jul 2017, 9:05 AM
Alok Singh
Alok Singh - avatar
+ 1
char func () {return a;} is it legal
21st Jul 2017, 9:26 AM
‎ ‏‏‎Anonymous Guy
+ 1
you can use return int; or return(int); but in char you can not use as return char; follow this code to know more #include <iostream> using namespace std; char printSomething() { return('a'); } int main() { char c; c=printSomething(); cout<<c; return 0; } this code will generate output char (a). by returning it from the function.
21st Jul 2017, 9:39 AM
Alok Singh
Alok Singh - avatar
+ 1
yes return a; in that program because a holds the value of 'g' and this will produce output 'g'.
21st Jul 2017, 12:50 PM
Alok Singh
Alok Singh - avatar
+ 1
tera account ke khilaf sakth kadam uthaya jae aisy developers se request karoonga tum is app pe rahne yogya nhi ho virus ho tum.
21st Jul 2017, 1:50 PM
Alok Singh
Alok Singh - avatar
+ 1
thik h jaa jo karna h kar
21st Jul 2017, 1:52 PM
‎ ‏‏‎Anonymous Guy
0
no I mean char printSomething(){ char a='g'; return a; //what will happen if I write return 0 } int main (){ char c; c=printSomething(); cout << c; return 0; }
21st Jul 2017, 10:27 AM
‎ ‏‏‎Anonymous Guy
0
output will nothing from this code.because you are using return 0;
21st Jul 2017, 11:59 AM
Alok Singh
Alok Singh - avatar
0
can you correct it
21st Jul 2017, 12:48 PM
‎ ‏‏‎Anonymous Guy
0
nahi hota h to naa bol
21st Jul 2017, 1:09 PM
‎ ‏‏‎Anonymous Guy