+8

Why can't I use void main in c++

c++

10/18/2019 7:21:19 AM

Hajji_firas

13 Answers

New Answer

+13

This is because the C++ standard requires main() to return int. As you probably know, the return value from the main() function is used by the runtime library as the exit code for the process. Both Unix and Win32 support the concept of a (small) integer returned from a process after it has finished. Returning a value from main() provides one way for the programmer to specify this value. If the code runs with no error then 0 is returned by the main()

+7

It has to do with the state of the compiler after the execution. 0 means normal termination while 1 means abnormal termination. Since the compiler needs to know the status of the code it uses the returned 0 or 1, which are of type int. It can return 1 as well, btw, AJ || ANANT || AC || ANANY || AY

+6

Because in C++ main method always return 0. That's why. It's predefined. Edited: In c++ main method either return 0 or 1.

+5

AJ || ANANT || AC || ANANY || AY Main function in C++ does not always return 0.

+4

Seb TheS & Prometheus [EXAMS]🇸🇬 Thanks

+4

Hajji_firas Abnormal termination is just a big word for "I don't think the code is working fine..." Normal termination is like "Everything is under control, even if something goes wrong"

+4

1. You can't use void main in C++ because the standard does not allow it. The main function is declared as int main. 2. The value returned from main is whatever the program designer wants it to be and means whatever the program documentation says it means, which is not always an error. See the documentation for the CHOICE, COMP and FC commands for example. https://ss64.com/nt/choice.html https://ss64.com/nt/comp.html https://ss64.com/nt/fc.html The value returned can even be negative. Understanding the concept of a return value from the main function is fundamental to understanding how programs interact with the shell/command line. I suppose that in these days of gui programs people are no longer used to command line usage or shell scripting and batch files.

+2

What is the difference bitween abnormal and normal code do you have an example for both

+1

You can use void main in different compiler like turbo, dev etc. But you have to use getch with it conio header file.

+1

Good

0

Can you give me a example of call by volue now

0

Ashu Singh Baghel Don't ask here. Ask in seperate thread so people can give answer.

-1