+ 2
Is it is compulsory to use return 0; in c++ program ?
in c language I faced that it is not compulsory to use return 0; rather to use getch ();
6 odpowiedzi
+ 2
Nope, it depends on the header of the main function. If you write it as int main() then you need to return 0 to the OS else if the header is void main(), you don't need to specify return value as it is by default 0.
Also, getch() is a function of class 'conio'. It returns the output available on the screen. If not included in the code, you need to open output window separately in order to view output.
Please do hit a 'like', if you find answer helpful!
+ 1
it is best practice to do so, because it is mandatory!
however, some compilers will insert it at the end of your main function if you forget, but not all will. either way it is needed for your program to run correctly.
this answer is for c++. i have very little knowledge of c.
+ 1
finally I came to know that it depends on the header file what we are adding.
+ 1
no simply use.. void main()
0
it is compulsory to return 0 because the main method has a return type of int. when writing a console application, getch() will wait for the user to input a character before continuing execution, which should pause the screen and stop it from closing immediately
- 1
not always,but if the header is int main it should return to the operating system