Thread: Passing arguments

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    186

    Passing arguments

    When you want to pass arguments to main one of the arguments is char *argv[]. To me this means pointer to array of characters. How is it possible then to pass more than one character long arguments. Obviously I know you can I just would like tounderstand

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It's an array of pointers. Each point points to an area of storage big enough to hold the argument.
    Regardless, in C++, you should use std::vector and std::string instead. And don't call main.
    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.

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Its a pointer to an array of pointers each pointing to an array of characters. Keep in mind that there is generally* no difference between a pointer to a type and a pointer to an array of that type.

    That particular syntax serves to emphasize that it is an array of char pointers. An array passed to a function degenerates to a pointer.

    The other equivelent way to declare argv is "char **argv". This states that argv is a pointer to one or more char pointers, which each could point to one or more chars.


    *is is possible to declare a pointer to an array, but it is never use because it is incompatible with dynamic arrays.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 11-21-2008, 04:27 PM
  2. Passing arguments between functions
    By Wiretron in forum C Programming
    Replies: 4
    Last Post: 05-17-2006, 04:59 PM
  3. Passing arguments to function...
    By alvifarooq in forum C++ Programming
    Replies: 8
    Last Post: 09-24-2004, 12:50 PM
  4. passing arguments
    By Baard in forum C++ Programming
    Replies: 3
    Last Post: 12-23-2003, 08:10 AM
  5. Question about Templates and passing arguments
    By supaben34 in forum C++ Programming
    Replies: 2
    Last Post: 10-13-2002, 01:32 AM