Header Ads

Basic Syntax - Objective C

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


Tokens in Objectiv-C
           A objective-c program, consist 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 consist of six tokens:

      NSLog(@"Hello my Friends");                                                                                                       

The individual tokens are:
NSLog                                                                                                                                                     
(                                                                                                                                                               @                                                                                                                                                               "Hello my friends"                                                                                                                                 
)                                                                                                                                                              
;                                                                                                                                                              


Semicolons:
In Objective-c program, the semicolon is a statement terminator. That is, each individual statement must be ended with a semicolon. It indicates the end of one logical entity.
For example, following are two different statements:

NSLog(@"Hello guys \n");                                                                                                                  
return 0;                                                                                                                                                


Comments
Comments are like helping text in your Objective-C program and they are ignored by the compiler. They start with /* and terminate with the character */ 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.



Identifiers
An objective-c identifier is a name used to identify a variable,function, or any other user-defined item. An identifier start with a letter A to Z or an underscore _ followed by zero or more letters,underscores and digits.(0 to 9)

Objectve-c does not allow punctuation character such as @, $, and % within identifiers. Objective-c is a case-sensetive programming langauge. Thus Manpower and manpower are two different identifier in objective-c. Here are some example of acceptable identifiers.:

mohd          zara                abc                  move_name                     a_123                                           
myname50          _temp        j                   a23b9                              ratValue                                        

Keywords 
The reserved wordes may not be used as constant or variable or any other identifier names.


Whitespace in Objective-C

A line containing only whitespace, possibly with a comment, is known as blank line, and an Objective-c compiler totally ignores it.
Whitespace is the term used in Objetive-c to describe blanks, tabs, newline character and comments.   Whitespace separates one part of a statement from another and enables the compiler to identify where one element in a statatemen,such as int,ends the next element begins.Therefore , in the following statement.:

int age;                                                                                                                                                     

There must be at least one whitespace character between int and age for the compiler to be able to distinguish them.The following statement,

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

no whitespace character are necessary between fruit and =, or between  = and apples, although you are free to include some if you wish for readability puepose.  

         

No comments:

Powered by Blogger.