In this tutorial we will learn about C tokens.
Its a set of characters that can be used to create values, variables, expressions etc.
Following are the characters that we can use in C programming language.
|DIGITS||All decimal digits 0-9|
|WHITE SPACE||Blank Space, Horizontal tab, Carriage Return, New Line, Form feed|
The smallest individual unit in a program is known as token.
Following are the tokens used in C programming language.
Keywords are the words that conveys a special meaning to the language compiler and are reserved for special purpose and hence must not be used as normal identifier name.
There are 32 keywords.
Identifiers are the fundamental building blocks of a program. They are used as the general terminology for the names givens to different parts of the program like the name of the variables, functions and arrays.
Identifiers name are user-defined and follow the following rules.
Example: name, _gameStatus, is_game_over, stage99 etc.
A value that will never change throughout the execution of the program is called a constant.
Example: 9.8 the value of g (acceleration due to gravity)
Following are the types of constants.
Integers are numbers without decimal parts and there are three types of integers namely decimal, octal and hexadecimal integers.
Decimal integers are in base 10 number system and uses 10 digits from 0 to 9.
Example: -9, 0, 10 etc.
Octal integers are in base 8 number system and uses 8 digits from 0 to 7 with a leading 0.
Example: 07, 017 etc.
Hexadecimal integers are in base 16 number system and uses 10 digits from 0 to 9 and 6 letters from A to F with leading 0x and 0X. Lowercase letters from a to f can also be used.
Example: 0x11, 0xAA, 0xbb, 0x12F etc.
Click here for tutorial series on conversion of numbers from decimal to binary, octal, hexadecimal number system.
These are the constants that have decimal parts and are also called as Floating Point Numbers.
Example: -10.234, 0, 3.14 etc.
We can also express real numbers in exponential form.
mantissa e exponent
Example: 1234 can be expressed in exponential form as
Similarly, -1200 can be expresses in exponential form as
A single character constant is a character enclosed in single quote.
Example: 'a', 'A', '1', '#' etc.
Character constants have integer value known as the ASCII value.
If we want to print the ASCII value of a character we can use the
printf("ASCII value of character 'A' is %d", 'A');
The above code will give the following output:
ASCII value of character 'A' is 65
Similarly, we can use the ASCII value to print the character.
printf("Character for the ASCII value 65 is %c", 65);
The above code will give us the following output.
Character for the ASCII value 65 is A
It is a sequence of characters enclosed in double quotes.
Example: "Hello World!"
A single character string constant like "A" does not have an ASCII value like a single character constant 'A'.
A string is a sequence of characters enclosed in double quotes.
Example: "Hey" is a string consisting of three characters 'H', 'e' and 'y'.
Operators are the symbols that are meant to perform some operation.
+ is an addition operator and we use it to add two numbers i.e., perform addition operation.
These are special backslash character constants.
Example: The following code will print "Hello World" and will move the cursor to the next line because of the new line character '\n'.