0
can you insert void main instead of int main?
I was wondering, if we can make the main function not return by using void main(). Putting return 0; is a bit waste of time.
6 Answers
+ 1
I did it and the compiler said void main() { must return a value,
I did void main() { cout<<"test"; return 0; } and it said it again.
so I can't do it.
+ 1
I was wrong because I use visual studio and that compiler accepts void so it depends on the compiler sorry
0
Most compilers will accept it and silently convert void to int. However, 'void main()' is just plain wrong and not valid C++.
0
void main is never valid C++. The standard only specifies int main. However, to not break existing code, some compilers accept void main and silently change it to int and return 0.
- 1
void datatype can be use for a function does not have to return a value. as main() does not require to return a value so void main() can be used
- 2
/* void main() is valid and used all the time since this function is usually not used to return a value. putting in return 0; is good coding and helps with warnings */ <-- wrong answer