+ 1
Can I use float as return type for main function. In c++.
Eg.float main(){ Return 9.8 ; } In codeblocks it shows error.
8 Answers
+ 2
No, int is the only valid return type for main.
The eax register of the cpu is used as a return value and it cannot store floating point values. ( x86 )
And they are too inaccurate anyway.
+ 2
No, you cannot. You used to be able to use void main() but that's been gone for a while. Now you can only use int main() which returns an integer value.
+ 1
But in Ubuntu float return type for main function is accepted.
It runs without any error. Why??
0
Some compilers allow all kinds of return values for main.
But anything other than int is not following the standard and is not portable.
I'd have to look through the assembly to be sure but it most likely just gets casted to an int.
( or undefined )
0
ABHISHEK GUPTA Certain compilers will allow it. Most C++ compilers used to have that feature but they started getting rid of it. Nowadays it's just easier and a normal practice to use int main() vs. anything else.
0
Can I run graphical program in codeblocks?
0
No, because when you return 0 in the main function, you are saying that que programm exits with no errors