Tokens
Marion Lester T. Raboy, Ph.D.
Token(s)
• A programming token is the most basic
component of a source code.
• The building blocks or the smallest individual
element in C.
• Types of C Tokens:
• Keywords, Literals or Constants, Strings, Identifiers,
Operators, and Special Characters or Symbols
Keywords
• It is defined as the reserved or pre-defined
words that hold their own importance.
• Every keyword has a functionality of its own.
• We cannot use them as the names of variables
or as identifiers.
32 Keywords of C
auto enum const goto
double case float default
struct register unsigned sizeof
int typedef short volatile
break extern continue if
else char for do
switch return void static
long union signed while
Literals
• Literals:
• Factual data represented in a language.
• Types of Literals:
• Numeric – uninterrupted sequence of digits (possibly containing a period).
• Example: 12345, 777, 99.99, 1.0
• Character – represents a single character and it is surrounded by single
quotation marks.
• Example: ‘A’, ‘$’, ‘4’
• String – a sequence of characters surrounded by double quotation marks.
• Example: “Hello World”, “A”, “100”
Constants
• A constant can hold only a single literal value during the
execution of a program.
• It means that once we assign value to the constant, then we
can't change it throughout the execution of a program- it
stays fixed.
• Two types of constants:
• Defined constants
• Declared constants
Identifiers
• Variable
• A named memory location which temporarily stores data that
can change while the program is running.
• The type of a variable indicates what kind of value it will store.
• Identifier
• Used for the naming of variable, function, class, structure or a
constant, etc.
• Once an identifier is declared, we can use the identifier
anywhere in the program to refer to the associated value.
Rules in Creating Identifiers
• The first character must always be an alphabet or an
underscore.
• It should be formed using only letters, numbers, or
underscore.
• A keyword cannot be used as an identifier.
• It should not contain any whitespace character.
• The name must be meaningful.
• Examples:
• Score_of_student, PaymentCode, House1, NewProd
Syntax in declaring Identifiers
• Examples:
• int Score;
• float PriceOfProduct;
• char Choice;
Note: this topic will be expounded on Data Types lesson.
#define
Syntax in defining Constants
• We define constants in the directive part of the
program. Examples:
• #define Score 100
• #define PriceOfProduct 69.99
• #define Choice ‘A’
Syntax in declaring Constants
• Examples:
• const int Score = 100;
• const float PriceOfProduct = 69.99;
• const char Choice = ‘A’;
Operators
• Operators are used with operands to build expressions.
Example of operators in red:
Total = Cost1 + Cost2
Counter--
if Gender != ‘M’ && Age < 18
Note: this topic will be expounded on Operators lesson.
Symbols, Punctuators or Special
Characters
• Symbols hold a special meaning that
we cannot use for any other purpose.
• Examples:
• Brackets • Period (union/structure)
{}()[]<> .
• Comma, semicolon • Tilde (destructor)
,; ~
• Asterisk (pointer)
*
• Hash/Preprocessor Directive
#