Code Translation

Discussion in 'iOS Programming' started by mav814, Mar 29, 2009.

  1. mav814 macrumors member

    mav814

    Joined:
    Mar 26, 2009
    #1
    Hey guys, I have been reading up on objective C and am already on the concepts of variables and objects but seemingly have skipped something because I am sure as to what the following string of code that I see a lot means..any help?

    Code:
    int main (int argc, const char * argv[])
     
  2. chbeer macrumors member

    chbeer

    Joined:
    Sep 22, 2008
    Location:
    Berlin
    #2
    1. It's a method with two parameters, the second being an array.
    2. It has a return type of int
    3. Last but not least this is the signature (name + parameters) of the main-method called when the program starts
     
  3. RutgerB macrumors newbie

    Joined:
    Jul 13, 2008
    #3
    This is the standard C function where your application starts.

    The arguments are the arguments you give when you run an application from the terminal. E.g.:

    application 2 hello world

    The first argument is the number of arguments given to the application and the second is an array of the different arguments.


    I don't think this is very important for iPhone developing since you won't run an iPhone app from the terminal. Correct me if I'm wrong because I just started developing for iPhone...
     
  4. admanimal macrumors 68040

    Joined:
    Apr 22, 2005
    #4
    Right, except you wouldn't actually have to specify the number of arguments on the command line. So if you typed what you have there, the value of argc in main would actually be 4 (yes, 4), and argv would be:

    argv[0] = "application" (always the name of the actual command)
    argv[1] = "2"
    argv[2] = "hello"
    argv[3] = "world"
     

Share This Page