CrazyEngineers Anniversary Celebrations Week : It's Raining Gadgets!

Participate in Online Contests During 24th-28th November, 2014 For A Chance To Win :

 

   

::Read Details::

Difference between int main and void main in C programming language?

Discussion in 'Computer Science | IT | Networking' started by Rahul Naraniya, Jul 19, 2014.

  1. Rahul Naraniya

    Rahul Naraniya Apprentice

    Engineering Discipline:
    IT
    can anyone explain what is difference between int main and void main??? why it is suggested to use int main instead of void main?? and why we need #include<conio.h> when we use int main???
     
    #1
  2. Deepika Bansal

    Engineering Discipline:
    Computer Science
    Difference betwèen int main and void main: See like any other function, main is also a function but with a special characteristic that the program execution always start from main. So the function main needs arguments and a return type. These int and void are its return type. Void means it will not return any value, which is also ok.
    But if want to know whether the program has terminated successfully or not, we need a return value which can be zero or a non zero value. Hence the functuon becomes int main () and is recommended over vpid main ().
    Hope its helps you.
     
    • Like Like x 2
    #2
  3. Rahul Naraniya

    Rahul Naraniya Apprentice

    Engineering Discipline:
    IT
    The same thing we can do by using getch() (for void main). then why int main is suggested?? is there any advantage of int main over void main??
     
    #3
  4. beingab

    beingab Rookie

    Engineering Discipline:
    Computer Science
    the standard statements are:
    int main(void)
    int main(int argc, char **argv)

    You can also use main() simply that means same as int main()..
    int main() returns an exit value to compiler and works on most compilers.
    And getch() as you mentioned has nothing to do with it. It gets character input on screen or else holds screen in other words
     
    #4
  5. Rahul Naraniya

    Rahul Naraniya Apprentice

    Engineering Discipline:
    IT
    ohk... got it thanks... :)
     
    #5

Share This Page