Unix C++
Would you like to react to this message? Create an account in a few clicks or log in to continue.

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

3 posters

Go down

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

Post by parvathy 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

Back to top Go down

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

Post by Christopher 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.
Christopher
Christopher
Admin

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

https://unixcpp.forumotion.com

Back to top Go down

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

Post by naga rishi 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 : 35
Location : KOLKATA

Back to top Go down

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

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

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

https://unixcpp.forumotion.com

Back to top Go down

error: return type for `main' changed to `int' Empty 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