In the simple program of hello world i tried 'return x' (x taking any value) instead of return 0 still it is working.Why? | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
0

In the simple program of hello world i tried 'return x' (x taking any value) instead of return 0 still it is working.Why?

13th Mar 2017, 3:19 AM
umesh
2 Réponses
+ 15
every function except void functions return a value it dependent in the function type which type of data it will return and int main() is also a user define function which is of integer type so it will return int value return 0 is written at the end of function for avoiding garbage returns by main () function
13th Mar 2017, 6:14 AM
Mansi Dagla
Mansi Dagla - avatar
+ 2
Yes, it is true. Because this returned value is not usually checked at all. But could be. In case you pass your program to another users (as coomercial, for example), they can check it . So the basic suggestion is : When you return another value from function main, write it in to program doceumentation or help....
13th Mar 2017, 6:06 AM
Petr Hatina
Petr Hatina - avatar