Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mav814

macrumors member
Original poster
Mar 26, 2009
37
0
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[])
 

chbeer

macrumors member
Sep 22, 2008
82
0
Berlin
  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
 

RutgerB

macrumors member
Jul 13, 2008
32
1
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...
 

admanimal

macrumors 68040
Apr 22, 2005
3,531
2
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.

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"
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.