Here are the topics which helps you in understanding the basic syntax of an Objective-C program
Let's start with tokens in Objective-C
Tokens is either a keyword, or an identifier, or a constant, or a string literals, or a symbol. An Objective-C program simply consists of various tokens. For instance, here is an statement consisting six tokens:
Here are the list of individual tokens from the above statement:
Semicolon is simply a statement terminator. In other words, each individual statement in Objective-C must be ended with a semicolon (;). Here is an example having two statements
NSLog(@"Hello, Semicolon\n"); return 0;
Comments are the text which are ignored by the compiler. In other words, comments are the text which can only be read by human, but ignored by the compiler.
Comments plays important role in reviewing the program later or debugging program, since these are just like helping text in an Objective-C program. Comments starts with /* and ends with */. Here is an example showing the comment:
/* this is a comment */
Here is one more example, also showing the comment:
/* This is objective-c basic syntax tutorial. * You are learning comments in Objective-C. * Comments helps in debugging the program */
Identifiers are the name used to identify a variable, function, or any other user-defined things. Here are the rules to follow for naming the identifier:
Here are some examples of valid identifiers in Objective-C:
Keywords are the reserved words having their special meaning and purpose. These reserved words can't be used as constants or variable or any other identifier names. Here, the following table lists the keywords in Objective-C:
In Objective-C, a line containing only whitespace, possibly with a comment, is known as a blank line, so an Objective-C compiler completely ignores it. Whitespace is used in Objective-C in describing the blanks, tabs, newline, etc.
Here is an example showing whitespace in Objective-C:
© Copyright 2021. All Rights Reserved.