Results 1 to 6 of 6

Thread: Float or character in place of int

  1. #1
    Geek_Guest
    Guest

    Float or character in place of int

    If we have any return type then we write int main().
    My question is that can we write float or character in place of int? if yes justify.

    Question asked by visitor anjali


  2. #2
    Expert Member
    Join Date
    Nov 2006
    Answers
    518

    Re: Float or character in place of int

    I think main() should return only int type value.

    Lack of WILL POWER has caused more failure than
    lack of INTELLIGENCE or ABILITY.

    -sutnarcha-

  3. #3
    Junior Member
    Join Date
    Aug 2007
    Answers
    8

    Re: Float or character in place of int

    main can return only two type of values according to me one is of void type and one is of int type.


  4. #4
    Junior Member
    Join Date
    Oct 2007
    Answers
    3

    Smile Re: Float or character in place of int

    The c & c++ standard say that the return type of the main() function must be int. Otherwise the behavior is undefined. Some good compilers(like gcc) even show an error msg when u use void or float main while some prehistoric compilers(like tc or tcc) dont.


  5. #5
    Junior Member
    Join Date
    Sep 2007
    Answers
    3

    Re: Float or character in place of int

    Hi...

    Do you know main() returns the value to whom? Who calls the main() at the beginning of execution of a program, that is the OS. The main() returns two values only, either 1 or 0 via int variable type to OS to notify the program execution successful or not. So it should be int type only. But in case of an argument anybody can say that it can return the same value via Float.... in that case the answer is here the binding goes between the main() & the OS. So it should maintain its strict signature.

    I'm not sure whether a conventional C/C++ compiler shows error if we use float instead of int or not, but it seems to me it's quite natural to accept float. Because after all compiler TC/TCC can provide so many strict parameters.....that's why they're more or less obsolete now.

    One more important point....we can easily refer Void instead of int because this means the main() wouldn't reply anything to the OS!! It's totally legal because it seems main() takes the total responsibilty about the success/failure of the execution of that program.

    Thanks,

    Kuntal


  6. #6
    Junior Member
    Join Date
    Oct 2007
    Answers
    3

    Re: Float or character in place of int

    The main() returns two values only, either 1 or 0 ::
    The main can return any integer value and any value other than 0(EXIT_SUCCESS actually) indicates that the program's execution was a failure. The value returned can be used to take necessary actions using a shell script(in unix environment).
    ...because it seems main() takes the total responsibilty about the success/failure of the execution of that program...
    Main() implicitly returns an EXIT_FAILURE only in cases where the program terminates unexpectedly. What if the user wants to return value 2 for an illegal input so that he can use it in his shell scripts? In such cases he must return the value all by himself. gcc actually makes it mandatory for the return value to be of int type to avoid any unexpected behavior.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact