When we use program (hello world )these are characters so why should we use int function ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

When we use program (hello world )these are characters so why should we use int function ?

Int main() Printf("hello wold");

12th Jan 2021, 2:16 AM
yashika rattu
yashika rattu - avatar
7 Answers
+ 6
yashika rattu , here you are not returning ("hello world") from the main() function but printing them on the console instead, your main() is still returning an integer only. According to the C/C++ standards, main() must return an integer after it's complition which will be returned to your operating system and is up to you if you want to use it or not. ( Generally used to find the status of program when it exited ) and the value you are returning doesn't matter if you are not using it for anything. As BeegCat said, if you do not write any return statement in main() then some morden compilers by default add it for you (only for the case of main() )
12th Jan 2021, 2:59 AM
Arsenic
Arsenic - avatar
+ 2
Thanks buddy šŸ‘
12th Jan 2021, 3:05 AM
yashika rattu
yashika rattu - avatar
+ 1
Every c or c ++ program must return an integer value to the machine. When it returns zero it means that the program finished the execution without errors, and when it returns any other number it means that there is an error. In other words, every c or c ++ program must return an integer for the machine.
12th Jan 2021, 2:24 AM
Daniel BriceƱo
Daniel BriceƱo - avatar
0
My doubt is not clearšŸ¤”
12th Jan 2021, 2:34 AM
yashika rattu
yashika rattu - avatar
0
I gotted that computer consist integers while program run or not . But now I have nothing to return so why should we use integer there should be use char function ?
12th Jan 2021, 2:36 AM
yashika rattu
yashika rattu - avatar
0
It is usually done like this: int main(){ return 0; } because that is how it indicates that everything ended as it should.
12th Jan 2021, 2:39 AM
Daniel BriceƱo
Daniel BriceƱo - avatar
0
try to return char to see how it comes out. remember that programming is made of magic and error
12th Jan 2021, 2:41 AM
Daniel BriceƱo
Daniel BriceƱo - avatar