Lecture-5 (23-09-2023)
Lecture-5 (23-09-2023)
MA144:
Computer Programming
Lecture-5
Tokens, Operators
Character Set
Tokens
Tokens - the smallest individual units in a program
Keywords
Identifiers
Constants
Strings
Operators
Special symbols
A C++ program is written using these tokens, white spaces,
and the syntax of the language.
The syntax for a programming language is the set of
grammar rules for that language.
Keywords
• Reserved identifiers (names) and cannot be used as names for
the program variables or other user-defined program elements
• Because they have predefined meaning in C++
Keywords (contd…)
words like cin and cout are not on the list of keywords
you are allowed to redefine these words,
hence they are not keywords
Avoid re-define these words
Identifiers
• Identifiers refer to the names of variables, functions, arrays,
classes, etc., created by the programmer.
• They are the fundamental requirement of any language.
• Each language has its own rules for naming these identifiers.
Rules to follow…
• Only alphabetic characters, digits and underscores are permitted.
• The name cannot start with a digit (but can start with underscore).
• Uppercase and lowercase letters are distinct.
• A declared keyword cannot be used as a variable name.
x 12
_x1 3X
x_1 _abc %change
ABC123z7 data-1
sum myfirst.c
RATE PROG.CPP
count Data abc
data2
Big_Bonus use meaningful identifiers as name
of the identifier
Variable Declarations
First rule of variable use:
Must declare a variable (by specifying its type and name)
before using it anywhere in your program
All variable declarations should ideally be at the beginning
of the main() or other functions ends with semicolon
Syntax
type var_name_1, var_name_2, var_name_3;
type – what kind of data we will be storing in the variable
int count=5;
int sum=a+b;
Output using cout object
• The operator << is called the insertion or put to operator.
• It inserts (or sends) the contents of the variable on its right to the
object on its left
cout << “Hellow world”;
cout << sum;
Input using cin object
• The operator >> is known as extraction or get from operator.
• It extracts (or takes) the value from the keyboard and assigns it
to the variable on its right
cin >> sum;
Output:
hai
hai
hai
hai
100
Data Types
• Integer type
• Floating-point type