History Class XII Ch. 3 Kinship, Caste and Class (1).pptx
C++ unit-1-part-7
1. Prepared By: Asst. Prof. Sejal Jadav
Unit-1
Principles of Object Oriented Programming Tokens,
expressions & Control Statements
(14 MARKS)
B.C.A & B.Sc.(IT) – 3
CS-13 C++ and Object Oriented
Programming
Prepared By: Asst. Prof. Sejal Jadav
2. Prepared By: Asst. Prof. Sejal Jadav
What are Token
• Each word and punctuation is referred to as a token in
C++. Tokens are the smallest building block or smallest
unit of a C++ program.
• These following tokens are available in C++:
• Identifiers, Keywords,
• Constants, Operators, Strings
3. Prepared By: Asst. Prof. Sejal Jadav
Identifiers
• Identifiers are names given to different entries such
as variables, structures, and functions. Also,
identifier names should have to be unique because
these entities are used in the execution of the
program.
4. Prepared By: Asst. Prof. Sejal Jadav
Rules for C++ Identifiers
• First character: The first character of the identifier in C++
should positively begin with either an alphabet or an
underscore. It means that it strictly cannot begin with a
number.
• No special characters: C++ does not encourage the use of
special characters while naming an identifier. It is evident that
we cannot use special characters like the exclamatory mark or
the “@” symbol.
5. Prepared By: Asst. Prof. Sejal Jadav
• No keywords: Using keywords as identifiers in C++ is
strictly forbidden, as they are reserved words that hold a
special meaning to the C++ compiler.
If used purposely, you would get a compilation error.
• No white spaces: Leaving a gap between identifiers is
discouraged. White spaces incorporate blank spaces,
newline, carriage return, and horizontal tab.
6. Prepared By: Asst. Prof. Sejal Jadav
•Word limit: The name of the identifier(variable)
must not exceed 32 characters, otherwise, it would
be insignificant.
•Case sensitive: Uppercase and lowercase are
distinct.
•Example
int num1; float amt;
char name; double principle_amt;
7. Prepared By: Asst. Prof. Sejal Jadav
Constants
• Constants refer to the fixed values that do not change during the
execution of a program.
Constant Type
123 Decimal integer
12.34 Floating point integer
o37 Octal integer
ox2 Hexadecimal integer
“C++” String
‘A’ Character
8. Prepared By: Asst. Prof. Sejal Jadav
Keywords
• Keywords are the explicitly reserved identifiers and cannot be
used as names for the program variables or other user defined
program elements.
asm double new switch
Auto else operator template
break enum private this
case extern protected throw
catch float public Try
char for register typedef
class friend return union
const goto short unsigned
continue if signed virtual
default inline sizeof void
delete int static volatile
Do long struct while
9. Prepared By: Asst. Prof. Sejal Jadav
Strings
• Strings refer to the sequence of characters that may include white
spaces.
• In C++ strings are enclosed with double inverted commas [“string
constant”]
Example
• “Hello Students” “Good Morning”
10. Prepared By: Asst. Prof. Sejal Jadav
Operators
• Input/output operators
• << output / insertion operator
• >> input / extraction operator
• Scope resolution operator
• ::
• Memory management
operators
• New-memory allocation
operator
• Delete-memory release operator
• Member dereferencing
operator
• ::* pointer-to-member declarator
• ->*pointer-to-member operator
• .* pointer-to-member operator
• Manipulators
• Endl-line feed operator
• Setw-field width operator
• Definition : An operator is a symbol that tells the compiler to
perform specific mathematical or logical manipulations.
11. Prepared By: Asst. Prof. Sejal Jadav
C++ Data Type
• All variables use data-type during declaration to restrict the
type of data to be stored.
• Therefore, we can say that data types are used to tell the
variables the type of data it can store.
• Whenever a variable is defined in C++, the compiler allocates
some memory for that variable based on the data-type with
which it is declared. Every data type requires a different
amount of memory.