Tokens in C (Character Set, Keywords and Identifiers)
Programming languages are used to write instructions, which can be used to communicate with computer systems. Just like any natural language, programming languages are just communicating mediums, so learning programming languages are very much similar to how we learn other natural languages like: English, Nepali , Hindi etc. First we need to learn alphabets, combine the alphabets to form words and then sentences. The analogy of learning C programming languages can be drawn from other natural languages as shown in figure below:
Character Set in C Programming
To represent basic information in the C programming language, we use character sets. Following tables list the basic character set used in C:
Alphabets |
[A - Z] [a - z] |
Digits |
0,1,2,3,4,5,6,7,8,9 |
Special Symbols |
` ~ @ # $I % ^ & * ( ) - _ + = { } [ ] | \ ; : “ ‘ , . > < ? / |
The alphabets , digits and special symbols shown above are called character set in C.
Constant Variables and Keywords
The computer systems are designed to perform computations and the computer stores the results of its computations in its memory. Memory in computer systems are storage device, it consist of millions of cell, and each cell store basic unit of information as shown below:
We store and retrieve information from these memory cells, each memory cell has its own physical address, to make cell access easier. Computer systems use these physical addresses to locate particular memory cells to store and retrieve information. However, as a user of computer system, it is impossible and very inconvenient to remember millions of these physical addresses, to make things simpler we can assign user defined name to these memory locations as follows:
Now, in the above diagram, X is a name assigned to one of these memory cells, initially it holds value 10 and then it is replaced by the value 25. As we can see the value of X keeps on changing, hence X is called variable here. Variables are the names assigned to the memory locations. In the above diagram, X is a variable and the values 10 and 25 are the constant entities.
In C programming language, Constants can be categorized as : a) Primary constants b) Secondary constants as follows:
Primary Constants |
|
Secondary Constants |
|
Keywords
Keywords are the reserved words in c programming languages. The meaning of these words are already assigned by compilers and hence it cannot be used as variable names in C programming language. There are total 32 reserved keywords in C programming, following tables shows the list of these reserve keywords:
auto, double, int, struct, break, else, long, switch, case, enum, register, typedef, char, extern, return, union, const, float, short, unsigned, continue, for, signed, void, default, goto, sizeof, volatile, do, if, static, while |
In the C programming language, Constants are called Literals and variables are called identifiers.
Variables and Rules for constructing Variable Name
Variables are the name given to memory locations, the values in these locations keep on changing. C programming language uses variable name to hold some values during program execution.
Since C is a formal language, constructing variable names should follow proper syntax and structure. Following are the rules to be followed for constructing variable name:
A particular variable type can hold values of the same type of constants. For example: integer variables can hold only integer constants, real/floating point variables hold value of real constants and character variables can only hold character constants. Therefore, while defining the variable name in C programming language, each variable is associated with its constant type, which is called DATA TYPE of that variable.