+ 1
Can the main function in C++ be of type void?
yesterday i tried to declare the main() to be of type void but i encountered an error.
7 Answers
+ 1
if u talk about c++ then yes in older complilers you can put a void return type for main
for example you can use it in older versions of Borland turbo and in 4.5 version also
but new compilers like Dev prohibits such a return type for main function if u insert int main (){//}
and not return anything or zero it will do perfectly without any warnings and errors
means no use of giving return type in Dev
0
me too
0
yes only if u r not returning a value.
0
Yes you can but it doesn't return a value
0
#include <iostream>
using namespace std;
main()
{
int a;
cout << "Please enter a number \n";
cin >> a;
cout << a;
}
0
In dev it will show error if u'll write void with main while if u compile it in turbo it will accept it.. In dev don't write anything before main like i have given one example of a program..
0
yes it can be of type void when you want to just print a message or something which does not require to write in that case u can use void as return type