error: return type for `main' changed to `int'
3 posters
error: return type for `main' changed to `int'
#include<iostream.h>
#include<conio.h>
void main()
{
cout<<"hi";
}
error:
..\ds.cpp:11: error: `main' must return `int'
..\ds.cpp:11: error: return type for `main' changed to `int'
Build error occurred, build is stopped
Note: if i change void main() to int main() i am getting output.....but i am not returning anything....
Why should i use int main()????
#include<conio.h>
void main()
{
cout<<"hi";
}
error:
..\ds.cpp:11: error: `main' must return `int'
..\ds.cpp:11: error: return type for `main' changed to `int'
Build error occurred, build is stopped
Note: if i change void main() to int main() i am getting output.....but i am not returning anything....
Why should i use int main()????
parvathy- Posts : 7
Points : 15
Join date : 2010-02-26
Re: error: return type for `main' changed to `int'
its all about C++ standard. according to C++ standard, it is "int main()". but few compilers accepts "void main()". so it depends on which compiler u use.
error: return type for `main' changed to `int'
Well! I think this might also be one of the reasons. when a function is executed, it should return some value (it may be void also). If the (main) function returns a value of 0 (of integer type),then the cpu understands that the program has executed successfully. So, that might be the reason why the return must be of integer type for main function. (to get the status of execution)
naga rishi- Posts : 8
Points : 3
Join date : 2010-03-08
Age : 35
Location : KOLKATA
Re: error: return type for `main' changed to `int'
yup. obviously. main should return a value to OS to check the successful execution of the pgm. But few compilers supports "void main()". but according to the standard, its "int main()"
Similar topics
» header file is not getting recognised (in Eclipse/C++)
» error in while loop
» Command error
» Identify the error in the code
» error in while loop
» Command error
» Identify the error in the code
Permissions in this forum:
You cannot reply to topics in this forum
|
|