Exforsys

Online Training

What is the differnce between.....

This is a discussion on What is the differnce between..... within the C and C++ forums, part of the Programming Talk category; What's the difference between main() / void main() / int main() / int main(void) / int main(int argc, char *argv[])...


Go Back   Exforsys > Programming Talk > C and C++

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 10-05-2006, 02:00 PM
Senior Member
 
Join Date: Apr 2006
Posts: 141
Adrian is on a distinguished road
What is the differnce between.....

What's the difference between main() / void main() / int main() / int main(void) / int main(int argc, char *argv[])
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 10-11-2006, 07:49 AM
Senior Member
 
Join Date: Mar 2005
Posts: 911
techguru is on a distinguished road
Quote:
Originally Posted by Adrian View Post
What's the difference between main() / void main() / int main() / int main(void) / int main(int argc, char *argv[])

int main ( void )
int main ( int argc, char *argv[] )
Slight variations of the above are acceptable, where 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.
The first option is used when you do not require access to the command line arguments.
The names argc and argv are identifiers that can be changed if you so desire, but sticking to argc/argv is convention. The return type of main() must always be an int, this allows a return code to be passed to the invoker.

for more ... Cprogramming.com: FAQ
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 11-06-2006, 09:09 AM
Junior Member
 
Join Date: Oct 2005
Posts: 1
viswanathrajuvk is on a distinguished road
I think, According to me
int main()
and
int main(void) has no difference. Both are same.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 11-06-2006, 02:12 PM
Senior Member
 
Join Date: Mar 2005
Posts: 911
techguru is on a distinguished road
I was reading at news groups... seems to be it's not clear,....


The first option is used when you do not require access to the command line arguments.

The return type of main() must always be an int, this allows a return code to be passed to the invoker.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 11-27-2006, 03:15 AM
Junior Member
 
Join Date: Nov 2006
Posts: 1
rash_i43 is on a distinguished road
void main() means returning the main() with void datatype.
int main() means returning the main() with int datatype.
int main(void) means returning the main() with int datatype and no argumernts.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 11-28-2006, 02:58 AM
Junior Member
 
Join Date: Nov 2006
Posts: 2
usha ranawade is on a distinguished road
answer by usha

when you write
1) main(), means it is a main() function using standard C syntax.
2) void main() means you are using ANSI C/C++ syntax.This function is not returning any data type i.e. nothing
3)int main() means you are using ANSI C/C++ syntax.This function is returning integer data type
4) int main(void) means you are using ANSI C/C++ syntax.This function is returning int data type and you are not passing any actual parameter.
5) int main(int argc, char *argv[]) means you are using ANSI C/C++ syntax.This function is returning int data type and you are passing parameters as a command line argument first parameter i.e.argc will store number of arguments whose data type is integer and second parameter will store actual arguments their data types are pointer to characters.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

Thread Thread Starter Forum Replies Last Post
What is differnce between EAC, WAC, LIN, or SRC. vegabonf Immigration Help 1 10-05-2004 08:06 PM


All times are GMT -4. The time now is 05:27 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0
Copyright 2004 - 2007 Exforsys Inc. All rights reserved.