argv confusion

This is a discussion on argv confusion within the C Programming forums, part of the General Programming Boards category; char **foo; /* a pointer to a pointer to char */ char *bar[]; /* an array of pointers to char, ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    75

    argv confusion


    char **foo; /* a pointer to a pointer to char */
    char *bar[]; /* an array of pointers to char, of unspecified size */

    *argv[] is nothing more than syntactic
    sugar for **argv (Note that this discussion is valid only for argv when used as function
    parameter. )
    I don't understand why *argv[] and **argv have the same meaning when used as a fct parameter.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,181
    An array is converted to a pointer to its first element when it is passed as an argument. A simpler example:
    Code:
    void print_numbers(int numbers[]);
    is equivalent to:
    Code:
    void print_numbers(int *numbers);
    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
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,919
    Because they mean exactly the same thing. You can't pass arrays. It's an illusion. You always pass a pointer to the first element instead. So the two syntaxes mean the same thing, but are typed differently.
    Code:
    void foo(int* numbers[]);
    is also equivalent to:
    Code:
    void foo(int** numbers);
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. argv
    By taurus in forum C Programming
    Replies: 15
    Last Post: 10-14-2007, 09:57 AM
  2. Using argc and argv data
    By Rad_Turnip in forum C Programming
    Replies: 4
    Last Post: 03-31-2006, 06:09 AM
  3. Converting a argc / argv construct into a va_list
    By chambece in forum C Programming
    Replies: 6
    Last Post: 07-03-2005, 05:47 PM
  4. how do i? re: argc - argv
    By luigi40 in forum C Programming
    Replies: 2
    Last Post: 06-11-2004, 11:17 AM
  5. more argv and argc
    By Unregistered in forum C Programming
    Replies: 6
    Last Post: 09-09-2001, 12:04 AM

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