View Full Version : Code Translation
mav814
Mar 29, 2009, 06:06 AM
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?
int main (int argc, const char * argv[])
chbeer
Mar 29, 2009, 07:19 AM
It's a method with two parameters, the second being an array.
It has a return type of int
Last but not least this is the signature (name + parameters) of the main-method called when the program starts
RutgerB
Mar 29, 2009, 07:29 AM
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
Mar 29, 2009, 08:55 AM
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"
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.