473,395 Members | 1,629 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,395 software developers and data experts.

why we use Void main ()

Dear sir/ madam,
I know a lot had been sad about the topic. But i want to know why it is so that teachers tends to use void along with main in every program they taught the class. When i ask the teacher, he never respond??
Please help.
May 3 '07 #1
6 3145
Another think that I want to know is that which is the best book so far to learn C for a newbie. please do respond to that fast, i really need the help.
May 3 '07 #2
JosAH
11,448 Expert 8TB
Using "void main(...)" is just dead wrong. Microsoft uses it all the time and that's
mostly the reason other people immitate that wrong behaviour. Both in C as well
as C++ the correct usage is to use one of those:
Expand|Select|Wrap|Line Numbers
  1. int main() { ... }
  2. int main(int argc, char* argv[]) { ... }
Using C++ a "return xxx" statement is optional in which case an implicit "return 0;"
is assumed at the end of the body of main(). C always requires an explicit return
statement, even if you'd just used an "exit(xxx);" at the end of the body of main().

Java uses a "public static void main(String[] args) method signature and I don't
know what C# does (I bet it's the same as Java).

For C and C++ however "void main(...)" is a big nono and your professor desrves
to be defenestrated or worse for using it ;-)

kind regards,

Jos
May 3 '07 #3
acoder
16,027 Expert Mod 8TB
This doesn't belong in the cafe, so I've moved it to the C/C++ forum.

Jos, what does "defenestrated" mean?!
May 3 '07 #4
svlsr2000
181 Expert 100+
what about the third agrument argp used in some places. I heard gcc/ linux uses third argument called argp, to pass environmental variables. please correct me if i am wrong
May 3 '07 #5
NeoPa
32,556 Expert Mod 16PB
Jos, what does "defenestrated" mean?!
I think that's "Thrown out the window!" :D
May 3 '07 #6
JosAH
11,448 Expert 8TB
I think that's "Thrown out the window!" :D
Yup, exactly right. I like that word, not just because not many people know
what it means but the action itself is just silly ;-) One person once interpreted it
as "to defenestrate your computer" == "install another (not Windows) OS on it".

kind regards,

Jos
May 3 '07 #7

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

Similar topics

192
by: Kwan Ting | last post by:
The_Sage, I see you've gotten yourself a twin asking for program in comp.lang.c++ . http://groups.google.co.uk/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&th=45cd1b289c71c33c&rnum=1 If you the oh so mighty...
7
by: Howard | last post by:
Hi all, with all the posts I see that have "void main()", and all the resulting corrections, I have to wonder...is there a commonly-used IDE out there that generates "void main()" by default...
16
by: Peter Ammon | last post by:
Often times, I'll have some malloc()'d data in a struct that need not change throughout the lifetime of the instance of the struct. Therefore, the field within the struct is declared a pointer to...
23
by: Eric J.Hu | last post by:
Hi, I have following code, want do pointer convert. It always complain: vcnvt.c: In function `main': vcnvt.c:20: warning: dereferencing `void *' pointer vcnvt.c:20: request for member `key'...
49
by: elmar | last post by:
Hi Clers, If I look at my ~200000 lines of C code programmed over the past 15 years, there is one annoying thing in this smart language, which somehow reduces the 'beauty' of the source code...
12
by: Bill Pursell | last post by:
The following code generates a compiler warning when compiled with gcc -pedantic: typedef (*FUNC)(int); FUNC f; void * get_f(void) { return &f;
48
by: Francine.Neary | last post by:
I've been reflecting on these two types of pointer. As far as I can glean from books, void * and char * are functionally equivalent: the key property of both is that they are pointers that can be...
36
by: x_knifer_x | last post by:
read the subject it says it all int main(void) is better than int main()
9
by: George2 | last post by:
Hello everyone, What is wrong with the code, I just want to allocate an array of 100 void* pointers. :-) int main() { void** p;
0
by: =?windows-1252?Q?Sch=FCle_Daniel?= | last post by:
Hi, $ cat main.cpp #include <iostream> //#define VOID void typedef void VOID; VOID foo() { std::cout << "in foo" << std::endl;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.