int main ( int argc, char **argv )

This is a discussion on int main ( int argc, char **argv ) within the C Programming forums, part of the General Programming Boards category; Hi, Code: int main ( int argc, char **argv ){} int main ( int argc, char *argv ) {} An ...

  1. #1
    Registered User
    Join Date
    Jun 2006
    Posts
    130

    int main ( int argc, char **argv )

    Hi,

    Code:
    int main ( int argc, char **argv ){}
    int main ( int argc, char *argv ) {}
    An array of char pointers can be represented as a function parameter one of two ways: char *name[] or char **name. I have chosen to use the latter, you can use either one, it is a matter of style, which I refuse to dictate
    This is quoted from FAQ : http://faq.cprogramming.com/cgi-bin/...&id=1073086407

    But, I am still confused between this and: http://www.cprogramming.com/tutorial/c/lesson14.html

    Can anyone explain that simply for me?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,647
    In the code you quoted, the former is correct, the latter is wrong. (But since this is C, both main functions should return 0.)

    Under certain circumstances, an array decays to a pointer to its first element. In that way, char **argv and char *argv[] are equivalent.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    char *argv .. u r sending a pointer to a char as an argument..this can be a normal pointer or point to a array of chars...


    char **argv .. u r sending a pointer to an array of pointers as an argument . which means, each element of this array can itself point to a char array..

    i hope this is clear enough

    and as u mentioned char **argv or char *argv[] are both the same

  4. #4
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,667
    char *argv ...
    This is wrong. Function prototypes must match exactly. laserlight nailed it.

  5. #5
    Eager young mind
    Join Date
    Jun 2006
    Posts
    342
    char *argv is wrong....i didnt say it was right..
    i just explained the diff between char *argv and char **argv.. was that wrong too??

  6. #6
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,667
    Nowhere in your statement did you tell the original poster that char *argv was not a valid parameter of main, so he might try to use it like that. Not to mention that you're posting to a thread that was answered clearly some three hours ago.

  7. #7
    Registered User
    Join Date
    Jun 2006
    Posts
    130
    Thanks all it is clear now

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to combine these working parts??
    By transgalactic2 in forum C Programming
    Replies: 0
    Last Post: 02-01-2009, 07:19 AM
  2. can some one please tell me the cause of the error ?
    By broli86 in forum C Programming
    Replies: 8
    Last Post: 06-26-2008, 08:36 PM
  3. Need help understanding info in a header file
    By hicpics in forum C Programming
    Replies: 8
    Last Post: 12-02-2005, 11:36 AM
  4. Can't Find Conio.h?
    By drdroid in forum C++ Programming
    Replies: 27
    Last Post: 09-26-2002, 04:24 AM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM

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