+ 1

Why the code ia showing error?

#include <iostream> using namespace std; void main() { int a; cout << "Please enter a number \n"; cin >> a; cout << a; }

31st Jan 2019, 5:48 AM
Manav Malhotra
Manav Malhotra - avatar
2 Réponses
+ 4
You need int main() instead of void main(), and return 0; at the end of main().
31st Jan 2019, 6:00 AM
Rowsej
Rowsej - avatar
+ 4
Yeah, what Rowsej said. Integer return type for main is a must. Returning 0 explicitly is optional though. The compiler adds it in for you if you don't write one in main(). http://www.stroustrup.com/bs_faq2.html#void-main
31st Jan 2019, 6:12 AM
Hatsy Rei
Hatsy Rei - avatar