Objective-C Basic Syntax


You have seen a basic structure of Objective-C program, so it will be easy to understand other basic building blocks of the Objective-C programming language.

Tokens in Objective-C

A Objective-C program consists of various tokens and a token is either a keyword, an identifier, a constant, a string literal, or a symbol. For example, the following Objective-C statement consists of six tokens:


The individual tokens are:

"Hello, World! \n"

Semicolons ;


For example, following are two different statements:

return 0;


Comments are like helping text in your Objective-C program and they are ignored by the compiler. They start with /* and terminate with the characters */ as shown below:

/* my first program in Objective-C */

You can not have comments with in comments and they do not occur within a string or character literals.



Objective-C does not allow punctuation characters such as @, $, and % within identifiers. Objective-C is a case-sensitive programming language. Thus, Manpower and manpower are two different identifiers in Objective-C. Here are some examples of acceptable identifiers:

mohd       zara    abc   move_name  a_123
myname50   _temp   j     a23b9      retVal


The following list shows few of the reserved words in Objective-C. These reserved words may not be used as constant or variable or any other identifier names.

auto else long switch
break enum register typedef
case extern return union
char float short unsigned
const for signed void
continue goto sizeof volatile
default if static while
do int struct _Packed
double protocol interface implementation
NSObject NSInteger NSNumber CGFloat
property nonatomic; retain strong
weak unsafe_unretained; readwrite readonly

Whitespace in Objective-C

A line containing only whitespace, possibly with a comment, is known as a blank line, and an Objective-C compiler totally ignores it.


int age;


fruit = apples + oranges;   // get the total fruit
