473,434 Members | 1,430 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,434 software developers and data experts.

what's the difference between int main() and void main()?

14
hlo, i've got a question , some people here gived me advice to use int main(),actually , i dont know what int main() is,but in my manual that i read ,the writer of the book says that i've got to use void main().
dont know what the problem is , help me!
Aug 14 '07 #1
5 8912
JosAH
11,448 Expert 8TB
hlo, i've got a question , some people here gived me advice to use int main(),actually , i dont know what int main() is,but in my manual that i read ,the writer of the book says that i've got to use void main().
dont know what the problem is , help me!
The difference is simple: 'void main()' is just plain wrong. Per the Standard the
return type of main should be int; the int value is used to supply the exit value
of the process that was started by invoking that same 'int main()' function.

It was Microsoft that started this 'void main()' nonsense because the return
values of their processes are very often ignored (for reasons that are beyond me),
but keep in mind: int main good, void main bad; and spread the word.

kind regards,

Jos
Aug 14 '07 #2
if you assign void main then it means that main function will not return any thing and you did not have to specify of return in main
if you assign int main then it means that main function will return a int value and you should specify a return statement in the main function otherwise you will get a warning by the compiler

and other thing is that some 32 bit compiler doesn't support void main and you have to specify int main in them
Aug 14 '07 #3
JosAH
11,448 Expert 8TB
and other thing is that some 32 bit compiler doesn't support void main and you have to specify int main in them
Those are called 'compliant' compilers, i.e. they comply with the Standard. Never
trust a C compiler that accepts 'void main()' without even a warning diagnostic.

kind regards,

Jos
Aug 14 '07 #4
dorkz
14
AH, you mean that void dont exist , that i must use int ?? and that int main() the head function is?
Aug 14 '07 #5
JosAH
11,448 Expert 8TB
AH, you mean that void dont exist , that i must use int ?? and that int main() the head function is?
Yep, void main() is just wrong. Here is what the C99 Standard has to say about it:

5.1.2.2.1 Program startup

[#1] The function called at program startup is named main.
The implementation declares no prototype for this function.
It shall be defined with a return type of int and with no
parameters:

int main(void) { /* ... */ }

or with two parameters (referred to here as argc and argv,
though any names may be used, as they are local to the
function in which they are declared):

int main(int argc, char *argv[]) { /* ... */ }

or equivalent;8) or in some other implementation-defined
manner.

[#2] If they are declared, the parameters to the main
function shall obey the following constraints:

-- The value of argc shall be nonnegative.

-- argv[argc] shall be a null pointer.

-- If the value of argc is greater than zero, the array
members argv[0] through argv[argc-1] inclusive shall
contain pointers to strings, which are given
implementation-defined values by the host environment
prior to program startup. The intent is to supply to

____________________

8) Thus, int can be replaced by a typedef name defined as
int, or the type of argv can be written as char ** argv,
and so on.
All the 'shall clauses' are considered mandatory.

kind regards,

Jos
Aug 14 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: jlopes | last post by:
I'm looking at the differences between these to forms and see no difference in their use. When accessed through a derived class. class ABase { public: virtual void filter(){ /* some code */ }...
17
by: ambar.shome | last post by:
Can anyone tell me : 1. void main() { char temp = "Hello"; temp='K';
83
by: rahul8143 | last post by:
hello, what is difference between sizeof("abcd") and strlen("abcd")? why both functions gives different output when applied to same string "abcd". I tried following example for that. #include...
35
by: Sunil | last post by:
Hi all, I am using gcc compiler in linux.I compiled a small program int main() { printf("char : %d\n",sizeof(char)); printf("unsigned char : ...
67
by: neilcancer | last post by:
i come from china,and i'm sorry that my english is very poor. now i'm studing data structure and i met some problem about c language. could you tell me what will happen after i use free()? i...
18
by: ben.carbery | last post by:
Hi, I have just written a simple program to get me started in C that calculates the number of days since your birthdate. One thing that confuses me about the program (even though it works) is...
5
by: Antonio Parolini | last post by:
What is the difference between: main(......) { exit(0); } and main(......) {
10
by: ravi | last post by:
Hi, i am a c++ programmer, now i want to learn programming in c also. so can anybody explain me the difference b/w call by reference and call by pointer (with example if possible).
20
by: Daniel.C | last post by:
Hello. I just copied this code from my book with no modification : #include <stdio.h> /* count characters in input; 1st version */ main() { long nc; nc = 0;
5
by: puzzlecracker | last post by:
C++ standard says the following: I am reading through c++ standard and have a difficulty understanding the difference between these two terms. Thanks, puzzlecracker
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.