C Tokens
C Tokens
C Tokens
Letters
Numbers
Special characters
White spaces (blank spaces)
A compiler always ignores the use of characters, but it is widely used for
formatting the data. Following is the character set in 'C' programming:
Letters
Uppercase characters (A-Z)
Lowercase characters (a-z)
Numbers
All the digits from 0 to 9
White spaces
Blank space
New line
Carriage return
Horizontal tab
Special characters
Special characters in 'C' are shown in the given table,
, (comma) { (opening curly bracket)
. (period) } (closing curly bracket)
; (semi-colon) [ (left bracket)
: (colon) ] (right bracket)
? (question mark) ( (opening left parenthesis)
' (apostrophe) ) (closing right parenthesis)
" (double quotation mark) & (ampersand)
! (exclamation mark) ^ (caret)
|(vertical bar) + (addition)
/ (forward slash) - (subtraction)
\ (backward slash) * (multiplication)
~ (tilde) / (division)
_ (underscore) > (greater than or closing angle bracket)
$ (dollar sign) < (less than or opening angle bracket)
% (percentage sign) # (hash sign)
Token
A token is the smallest unit in a 'C' program. A token is divided into six
different types as follows,
Tokens in C
Keywords and Identifiers
In 'C' every word can be either a keyword or an identifier.
Keywords have fixed meanings, and the meaning cannot be changed. They
act as a building block of a 'C' program. There are total 32 keywords in 'C'.
Keywords are written in lowercase letters.
Example: Height, age, are the meaningful variables that represent the
purpose it is being used for. Height variable can be used to store a height
value. Age variable can be used to store the age of a person
A variable must be declared first before it is used somewhere inside the
program. A variable name is formed using characters, digits and an
underscore.
Following are the rules that must be followed while creating a variable:
1height
Hei$ght
My name
int my_variable;
my_variable = 48;
By the way, we can both declare and initialize (assign an initial value) a
variable in a single statement:
Data types
'C' provides various data types to make it easy for a programmer to select a
suitable data type as per the requirements of an application. Following are
the three data types:
Each data type differs in range even though it belongs to the integer data type
family. The size may not change for each data type of integer family.
The short int is mostly used for storing small numbers, int is used for storing
averagely sized integer values, and long int is used for storing large integer
values.
Whenever we want to use an integer data type, we have place int before the
identifier such as,
int age;
Here, age is a variable of an integer data type which can be used to store
integer values.
float division;
double BankBalance;
Character data type
Character data types are used to store a single character value enclosed in
single quotes.
Example,
Char letter;
Void data type
A void data type doesn't contain or return any value. It is mostly used for
defining functions in 'C'.
Example,
void displayData()
Type declaration of a variable
int main() {
int x, y;
float salary = 13.48;
char letter = 'K';
x = 25;
y = 34;
int z = x+y;
printf("%d \n", z);
printf("%f \n", salary);
printf("%c \n", letter);
return 0;}
Output:
59
13.480000
K
We can declare multiple variables with the same data type on a single line by
separating them with a comma. Also, notice the use of format specifiers in
printf output function float (%f) and char (%c) and int (%d).
Constants
Constants are the fixed values that never change during the execution of a
program. Following are the various types of constants:
Integer constants
An integer constant is nothing but a value consisting of digits or numbers.
These values never change during the execution of a program. Integer
constants can be octal, decimal and hexadecimal.
The octal and hexadecimal integer constants are very rarely used in
programming with 'C'.
Character constants
A character constant contains only a single character enclosed within a single
quote (''). We can also represent character constant by providing ASCII value
of it.
String constants
A string constant contains a sequence of characters enclosed within double
quotes ("").
Real Constants
Like integer constants that always contains an integer value. 'C' also provides
real constants that contain a decimal point or a fraction value. The real
constants are also called as floating point constants. The real constant
contains a decimal point and a fractional value.
Mantissa e Exponent
For example, to declare a value that does not change like the classic circle
constant PI, there are two ways to declare this constant