Tokens, Expressions and Control Structures
Tokens, Expressions and Control Structures
Tokens, Expressions and Control Structures
Chapter 3
~ Tokens, Expressions
and Control Structures
Tokens
The smallest individual units in a program are known as tokens
Keywords Identifiers
Constants Strings
Operators
“wchar_t” type is a wide character literal intended for character sets that cannot fit a
character into a single byte
Basic Data Types
C++ data
types
enumeration references
Uses of void
to specify return type of a function when it is not returning any
value
to indicate an empty argument list to a function
declaration of generic pointers
void *gp; gp is a generic pointer
We can say,
Unions are memory-efficient alternatives of structures
particularly in situations where it is not required to access the
different member elements simultaneously
Structures Unions
1. defined with ‘struct’ keyword 1. defined with ‘union’ keyword
2. all members can be 2. only one member can be
manipulated simultaneously manipulated at a time
3. size of a structure object is 3. size of union is equal to the size
equal to the sum of individual of largest member object
sizes of the member objects 4. union members share
4. allocated distinct memory common memory space for
locations their exclusive usage
5. are not memory efficient when 5. memory efficient when
compared to unions members are not required to
6. structures in C++ behave just be accessed simultaneously
like a class 6. retain their core functionality
Enumerated Data Type:
provides a way for attaching names to members
keyword used – enum
syntax is similar to structure:
eg. enum shape {circle, square, triangle}
0 1 2
Here shape becomes a new data type using which we can
declare new variables
By default, enumerators are assigned integer values starting
from 0 and so on
An enum within a class is local to that class only
Storage Classes:
Automatic External Static Register
Functions :
(Chapter 4)
Symbolic Constants
There are two ways of creating symbolic constants:
~ using qualifier ‘const’ and
~ defining a set of integer constants using enum keyword
➢ const in C++ are local, however they can be made global using
keyword extern
➢ enum { X=100, Y=50, Z=200};
• Implicit Conversions:
➢ Whenever data types are mixed in an expression, C++ performs the
conversion automatically. This process is known as implicit or
automatic conversion.
Nandini Sidana