error: return type for `main' changed to `int'

Go down

error: return type for `main' changed to `int'

Post by parvathy on Fri Feb 26, 2010 6:35 pm

#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()????

parvathy

Posts : 7
Points : 15
Join date : 2010-02-26

View user profile

Back to top Go down

Re: error: return type for `main' changed to `int'

Post by Christopher on Fri Feb 26, 2010 7:00 pm

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.
avatar
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 30

View user profile http://unixcpp.forumotion.com

Back to top Go down

error: return type for `main' changed to `int'

Post by naga rishi on Tue Mar 09, 2010 5:43 pm

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 : 30
Location : KOLKATA

View user profile

Back to top Go down

Re: error: return type for `main' changed to `int'

Post by Christopher on Tue Mar 09, 2010 5:57 pm

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()"
avatar
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 30

View user profile http://unixcpp.forumotion.com

Back to top Go down

Re: error: return type for `main' changed to `int'

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum