void main(), int main(), argc, argv[]????

This is a discussion on void main(), int main(), argc, argv[]???? within the C Programming forums, part of the General Programming Boards category; I read somewhere it is good etiquette to use int main().....I understand that 'argc' is the number of parameters handed ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    2

    Question void main(), int main(), argc, argv[]????

    I read somewhere it is good etiquette to use int main().....I understand that 'argc' is the number of parameters handed to main(), and 'argv[]' is an array of char pointers to the parameters.......but am still a little confused.
    Am currently learning C, have written some pretty wicked programs, and about to send them in to be marked. All the example code I have ever seen used void main(). My programs work ok with void main(), but if int main() is the standard I want to use it.

    Do programs written for industry always use argc & argv[]?
    Does this mean the programs must be loaded from the command line?
    Should argc & argv[] be tested in some way?
    Can int main() be used without argc & argv[]?
    What is the difference?
    Do you know of a good web site to explain all this for me???

  2. #2
    Registered User C_Coder's Avatar
    Join Date
    Oct 2001
    Posts
    523
    as for the int main v void main issue !read!
    All spelling mistakes, syntatical errors and stupid comments are intentional.

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >I read somewhere it is good etiquette to use int main().....
    No, it is correct to use int main, anything else is just plain wrong.

    >My programs work ok with void main()
    Maybe for you on your system, but using void main might reformat my hard drive or fry some poor guy's monitor.

    >but if int main() is the standard I want to use it.
    And this is why I still have hope for the future of programming

    >Do programs written for industry always use argc & argv[]?
    No

    >Does this mean the programs must be loaded from the command line?
    No

    >Should argc & argv[] be tested in some way?
    Why should you test values? The user is an intelligent person who always uses the program in the way it should be used, right?

    >Can int main() be used without argc & argv[]?
    Yes, the other standard way of using main is
    int main ( void )

    >What is the difference?
    What is the difference between
    int function ( void )
    and
    int function ( int i )
    One takes arguments that can be used in the function, the other does not.

    >Do you know of a good web site to explain all this for me???
    If you'll read this line and then look down a few lines.


    No, a few more.


    Just a couple more you'll see two links in my signature, one is a C FAQ with your answers.

    -Prelude
    My best code is written with the delete key.

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    197
    Always use
    Code:
    int main(void)
    {
    
       /* CODE */
    
      return 0;
    }
    or
    Code:
    int main(int argc, char *argv[])
    {
    
      /* CODE */
    
      return 0;
    }
    itīs absolutely correct and standard-conform.

    klausi
    When I close my eyes nobody can see me...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  2. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  3. Replies: 2
    Last Post: 03-24-2006, 07:36 PM
  4. Converted from Dev-C++ 4 to Dev-C++ 5
    By Wraithan in forum C++ Programming
    Replies: 8
    Last Post: 12-03-2005, 06:45 AM
  5. Quack! It doesn't work! >.<
    By *Michelle* in forum C++ Programming
    Replies: 8
    Last Post: 03-01-2003, 11:26 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21