CrazyEngineers Archive
Old, but evergreen and popular discussions on CrazyEngineers, presented to you in read-only mode.
@Rahul Naraniya • 19 Jul, 2014
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???
@Deepika Bansal • 19 Jul, 2014 • 4 likes 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.
@Rahul Naraniya • 19 Jul, 2014 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??
@beingab • 19 Jul, 2014 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
@Rahul Naraniya • 20 Jul, 2014 ohk... got it thanks... 😀
@ravirajput • 25 Jan, 2015 goood yr...
@SK Jindal • 25 Jan, 2015
Rahul Naraniya
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 [HASHTAG]#include[/HASHTAG]<conio.h> when we use int main???
void implies no return type and int main means that main() will return an integer
@kothandaraman • 07 Jul, 2015 • 1 like
#include<stdio.h>
void main()
{
clrscr();
add(5,4);
getch();
}
int add(int a,int b)
{
int c;
c=a+b;
printf("Output: %d",c);
return 0;
}
now see the guys when you use the function having some parameters than time return some a and b values so now use int main function
if use void add(int a,int b) system throw the error. so i use int add(int a,int b)
@kothandaraman • 07 Jul, 2015 • 1 like above the program any doubt message me
@rahul69 • 07 Jul, 2015 1. int main() is preferred over void main(), as per standards, and most new compilers supports int main() rather than void main().
2. int main() can help to return the error code if your program fails due to some error.
(Pre exception handling days, now you may use exception handling to handle issues,
perhaps that's the reason in java we go as public static void main () )
😀
@Gowtham369369 • 09 Jul, 2017 i have replaced void main() with int main() there is same result then what is the difference......?
@Walter Boyd • 10 Jul, 2017 The difference is, in C, int main() can be called with any number of arguments, but int main(void)can only be called without any argument. Although it doesn’t make any difference most of the times, using “int main(void)” is a recommended practice in C.
@Gowtham369369 • 10 Jul, 2017 Okay! then I will use only int main() so that there will be no confusion for me....
@Base Developer • 17 Aug, 2018

How can I came to know that program is returning a value after using int main function


@GEETHA NANI • 14 Jan, 2019

can anyone suggest me a video of difference between this void main and int main

@GEETHA NANI • 14 Jan, 2019 • 1 like

can anyone suggest me a video of difference between this void main and int main

@Ankit Anand • 16 Jan, 2019 • 1 like

The above program has compilation error because we must define the add method before main method 

@AdhikariHarika Reshma • 17 Jan, 2019 • 2 likes

https://youtu.be/7aC5eLd9bY4

@GEETHA NANI hope the above link for the difference between INT main and void main help you.

@supriya VN gowda • 19 Jan, 2020 • 1 like

Both int main() and void main() are return types used in all programming languages. void main() is supported by C but other programming languages does not support void main(). int main() is used by all the programming languages. void meaning null and it does not return any value and int main() will return value. conio.h standard library is used for console input and output. getch() is present in conio.h standard library so C uses conio.h library, if we use void main() its compulsory to use getch() as return type. It's better to use int main() instead of void main() for effective programming.

@Divisha Madupalli • 15 Feb, 2020 • 1 like

void main() indicates that the main() function will not return any value, but the int main() indicates that the main() can return integer type data. 

The program is not going to terminate before reaching the last line of the code, or when the code is error-free, then we can use the void main(). 

If we want to terminate the program using exit() method, then we have to return some integer values (zero or non-zero) then we use int main().

@Karshil Sheth • 15 Feb, 2020 • 1 like

First int main is used for returning the value from a function. If you want to return a value say 5 from the function then you need to explicitly defined Int before the function name. If you dont want to return anything then declare void. 

Conio is used for input/output. Eg:- printf statements

@Noothan Kumar • 15 Feb, 2020 • 1 like

main(): program execution starts from the main() function. Every C program must contain a main() function. The main function may contain any number of statements. These statements are executed sequentially in the order which they are written.

void main() Vs. int main(): main is a function 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 okay.

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 function becomes int main () and is recommended over void main ().

@Mohana Chandra • 24 Feb, 2020

Program Execution begins from main method.

Int main()  : It is the main method with return type 'integer' and with no arguments or parameters.When the program uses exit() method to terminate, then it is recommended to use int main() because it returns some integers.

void main(: This main method is with no arguments,return type "void" which means that, this main method will not return any value.When the code is error free,then it is recommended to use void main(). 

51.4k views

Related Posts

@Ankita Katdare · Jul 17, 2015

From the official CDAC website it is confirmed that the CDAC DASDM or Diploma in Advanced Software Development Methodologies course is aimed for those who want to enter the field...
5.9k views

@Ankita Katdare · Feb 7, 2015

Two programmers with passion for developing a fast browser that runs on limited hardware, started developing it in 1994. The product of their ideas was what we saw as Opera....
6k views

@Kaustubh Katdare · Nov 5, 2012

Problem: You tried to install Windows on your Mac via OSX inbuilt BootCamp utility and the installation didn't went through properly OR you removed Windows from your Mac which you...
4.7k views

@Kaustubh Katdare · Mar 15, 2010

CEans, I'm sure you have heard that Facebook is opening an office in Hyderabad, India. They will be hiring sales & operations people. Those who wish to apply for jobs...
9.4k views

@jyoti_rocks · Aug 3, 2015

Whats the package at MPHASIS for freshers?
6.2k views