Wednesday, March 23, 2011

Analyzing Apple's HelloWorld Program

HelloWorld.m contains the following:

1 #import <Foundation/Foundation.h>
3 int main (int argc, const char * argv[]) {
4     NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
6     // insert code here...
7     NSLog(@&quot;Hello, World!&quot;);
8     [pool drain];
9     return 0;
10 }

Line 1 is an #import statement, which behaves just like it does in Java, or like #include in C/C++
Line 3 is main... which should look familiar from countless other languages
Line 4 creates a "pool" of memory so that your program can use it
Line 6 is a one line comment. Multiple line comments follow the /* text */ format, like most languages
Line 7 is a print statement. The @ makes this line a format string as opposed to a C string
Line 8 gives the borrowed memory back to the machine
Line 9 is the return statement for this program (used to pass errors to the operating system)


  1. This made me remember my programming days.

  2. Nice post; it's great for the less technologically inclined in the area of coding to get a feel for what each line does.

  3. Nice one! Did some programming for a while..getting a but rusty though :P
    +1 follower :)

  4. I don't know if I like a language that has a pointer in its "Hello World" program...