Saturday, 10 August 2013

Tokens and Identifiers in C

Welcome to Wind Trainers :: Trainers, C, Tutorials, Programming, Java, VB.net, C++, ANSI, Learn C, Learn Programming
Forum | Contact

C Tutorials


| Tokens |


A token is either a keyword, an identifier, a constant, a string literal. For example
printf
(
"Hello World"
;

| Semicolons |

The semicolon is a statement terminator.Each individual statement must be ended with a semicolon. It indicates the end of one logical entity. For example, following are two different statements:
printf("\n Hello World");
return 0;

| Comments |


Comments are like helping text in your C program and they are ignored by the compiler. They start with /* and terminates with the characters */ as shown below:
/* My first C Program */
We can not have comments with in comments and they do not occur within a string or character literals.

| Identifiers |

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

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

wind abc a_name a_123
cpro50 _var x cName x1y

| Keywords |


C has predefined list of keywords which cannot used for any other purpose like varibale name or any other identifier. Following is the list of keywords in C.

auto static long switch
break enum register typedef
case extern return union
char float short unsigned
const for signed void
continue goto sizeof volatile
default if else while
do int struct _Packed
double      


| White Spaces |

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

Whitespace is the term used in C to describe blanks, tabs, newline characters and comments. Whitespace separates one part of a statement from another and enables the compiler to identify where one element in a statement, such as int, ends and the next element begins. Therefore, in the following statement:

int class;

There must be at least one whitespace character (usually a space) between int and class for the compiler to be able to distinguish them.

name = wind + trainers

No whitespace characters are necessary between name and =, or between = and wind, although we are free to include some if you wish for readability purpose.

No comments:

Post a Comment