C CHARACTER SET
Just like the character set of English (a,b,c etc), a computer language has also its own character sets.The C has the following character set :
Letters : A-Z, a-z
Digits : 0-9
Special symbols : + - * / ; : ' " < > ! @ # $ % ^ & * ( ) _ . , ? / = { } [ ]
White spaces : Blank space, horizontal tab, Carriage Return, Newline, form feed
Other character any of 256 ASCII codes.
Our English have only 26 alphabets in character set but in C language, its a vast collection. Since we discussed that language is user friendly i.e. it can be understandable by the human that's why it uses the general English letters, digits and special symbols.
TOKENS
The bookish definition says “The smallest individual unit in a program is known as a Token”. Now let us talk about it, what is the smallest unit? Okey so here it is. Say take a sentence “I love Football”. Here "i", "love" and "football" are the smallest unit. Same way in programming, every single word of the codes is called tokens.Types of Tokens are :
• Keywords
• Identifiers
• Literals
• Punctuators
• Operators
Now let us know each one of them one by one.
Keywords
Keywords are the words which have some special meaning and which can be understood by the compiler.You might think that what is compiler? A compiler is a tool or program which compiles or builds your program and search for any error in the program or not. Let us take a real example. Suppose you wrote a speech for president. But you are not sure that each and every line is correct or not. So you will provide the speech to the person who is expert in grammar and spellings. He will mark the errors and will give you hint to correct it. And after correcting you will give him again and if everything is OK then you can give the speech to the president. So this “expert” is the compiler.
Let us relate it now with programming. You wrote a program and you compiled it while compiling the compiler will show you the errors and will provide you the hint to correct. Once all errors are cleaned then the program is free to run.
Let’s come back to the main topic i.e. keywords. These keywords are the words which have special meaning and so that the compiler can understand it. For example in English language, the words available in the dictionary (e.g. football, cake etc) are the keywords. Each word has their special meaning and we can’t change the meaning or the words.
The standard Keyword Sets of C are :
auto extern sizeof break floatn static
case for struct char goto switch
const if typedef continue int union
default long unsigned do register void
double return volatile else short while
enum signed
C programming can recognize other keywords too, which you will get in your higher level of studies.
Points to be remember about keywords :
- Keywords are the reserved words and must not be used as an Identifier.
- Keywords should always be in lowercase.
Identifiers
Identifiers are the names which are given to the different elements presented in a program. Let us take it in the real world situation.Suppose you have a brother and he don’t have a name. You keep his name “Football”, will it be okey? Lets find it out. Suppose you want to say that you are having with your brother, the sentence will be like “I am having my breakfast with my brother football”. Is it meaningful? No right? So what we conclude from it? Lets discuss about the rules to set an identifier.
The rules are :
- An Identifier cannot be a keyword.
- It is case sensitive i.e. “A” and “a” are different.
No special symbol van be included. The underscore (_) can be used since it is considered as a letter.
Blank spaces between the identifier name are not allowed.
Some example of valid identifiers are :
a a5 del_1 _name convert_temp SUM
Some examples of Invalid identifiers are :
1st Started with a digit.
First name Space between the identifier names.
Roll-No Special character (-) used.
“name” Special character (“) used.
Literals
Literals are also known as constants. You know what constants are, same are the literals. Literals are the data items which never changed the value during a program run.The different types of literals are :
- Integer-constant
- Floating-constant
- Character-constant
- String-constant
Integer Constant : Digits are come in integer constant like say 2. You cannot say that 2 is 5 or 2 is 9 etc. So the value of 2 is fixed.
Floating Constant : Digits with decimal values. For eg. 5.14, 6.09 etc.
Character Constant : It consists of a single letter and can be written in single quote. Eg. ‘a’.
String Constant : It consists of a series of letters like a word or a sentence and written in double quote. Eg “num”.
Punctuators
You might get punctuators in grammar. Right? If not, then it’s okay. We are going to discuss in this section. Characters like . , ; : ( ) { } [ ] = # etc are known as punctuators.
In an English language, suppose you wrote “I love myself I love all”, Will it be consider as accurate? No. Because, there is no full stop. The line should be “I love myself. I love all.” Same way in computer language, a small punctuation error may stop the program from running. We will use it in our programs and slowly you will come to know the function of each one of them.
Operators
What are operators? Operators are those which operate something. Now what is that something? That something is the variables and other objects. Now what are variables? We will discuss on variables in our upcoming topics.So simply we can say that operator is those which compute the values when applied to the variables or other object.
There are different types of operators:
Arithmetic Operators + - * / %
Unary Operator
Relational Operator < > <= >= == !=
Logical Operator || &&
Assignment operator = *= /= %=
Conditional operator ? :