You are on page 1of 21

‫بسم ہللا الرحمن الرحیم‬

Comments:-
Comments are the lines of a
program that are not executed.
These lines are made to understand the
program easily by the programmer.
 These lines are written in High level
language (source program) but not
compiled ,so these lines are not
present in object code or object
program.
 Comments don’t affect the size of a
program.
 These are the lines that made
program easy to understand for the
programmer.
 Comments are for the readers, not
for the compiler.
Types of comments:
There are two types of comments
which are following:
1. Single line comments.
2. Multi line comments.

Single line comments:


This comments are used to
represent a single line of a program.
 It is represented by slashes.
 Single line comments begins
with//.
 The // (two slashes) characters,
followed by any sequence of
characters.
For example:
1. int a;
//variable declaration

2. //it is C++ program.


3. //Welcome to C++
programming.

Multi line comments:


These lines represent multiple
lines of a program.
 These are represented by slash
and asterisk.
 Multi line comments are enclosed
in between /* and */.
 The /* (slash, asterisk) characters,
followed by any sequence of
characters (including new lines),
followed by the */ characters. This
syntax is the same as ANSI C.
For example:
1. int a=10;
/*variable declaration at a time of
initialization*/
Token:
A token is the smallest element
of a program that is meaningful to
the compiler.
 It is the smallest unit of a
program written in any
language.

Tokens can be classified as


follows:
 Keywords.
 Identifiers.

C++ tokens includes:


 Special symbols
 Word symbols
 Identifiers
Special symbols in C++ includes:

+ - * /
. ; ? ,
<= != == >=

Reserved words:
A reserved word is a word
that cannot be used as an
identifier, such as the name
of a variable, function, or
label.
 It is definition, and a
reserved word may have no
meaning.
 These cannot be defined in a
program.
 These cannot be used for
anything other than their
intended use.

For example:
int
float
double
char
const
void
return
Identifiers:-

Identifiers are the name of


something that appears in a program

 These consists of letters,


digits, and the underscore
character (_).

 These must begin with a


letter or underscore.

 C++ is case sensitive.


For example:
NUMBER is not the same as
number

 Two predefined identifiers


are cout and cin.

 Unlike reserved words,


predefined identifiers may
be redefined, but it is not a
good idea.

 Legal identifiers in C++:


first
conversion
payRate.
An identifier is a sequence of
characters used to denote one of the
following:
 Object or variable name
 Class, structure, or union name
 Enumerated type name
 Member of a class, structure,
union, or enumeration
 Function or class-member
function
 typedef name
 Label name
 Macro name
 Macro parameter
The following characters are allowed
as any character of an identifier:

a b c d e f g h i j k l m
n o p q r s t u v w x y z
A B C D E F G H I J K L M
N O P Q R S T U V W X Y Z
Certain ranges of universal character
names are also allowed in an
identifier. A universal character name
in an identifier cannot designate a
control character or a character in the
basic source character set. These
Unicode code point number ranges
are allowed as universal character
names for any character in an
identifier:
 00A8, 00AA, 00AD, 00AF, 00B2-
00B5, 00B7-00BA, 00BC-00BE,
00C0-00D6, 00D8-00F6, 00F8-
00FF, 0100-02FF, 0370-167F,
1681-180D, 180F-1DBF, 1E00-
1FFF, 200B-200D, 202A-202E,
203F-2040, 2054, 2060-206F,
2070-20CF, 2100-218F, 2460-
24FF, 2776-2793, 2C00-2DFF,
2E80-2FFF, 3004-3007, 3021-
302F, 3031-303F, 3040-D7FF,
F900-FD3D, FD40-FDCF, FDF0-
FE1F, FE30-FE44, FE47-FFFD,
10000-1FFFD, 20000-2FFFD,
30000-3FFFD, 40000-4FFFD,
50000-5FFFD, 60000-6FFFD,
70000-7FFFD, 80000-8FFFD,
90000-9FFFD, A0000-AFFFD,
B0000-BFFFD, C0000-CFFFD,
D0000-DFFFD, E0000-EFFFD
The following characters are allowed
as any character in an identifier
except the first:

0 1 2 3 4 5 6 7 8 9
These Unicode code point number
ranges are also allowed as universal
character names for any character in
an identifier except the first:
 0300-036F, 1DC0-1DFF, 20D0-
20FF, FE20-FE2F
Microsoft Specific:
Only the first 2048 characters of
Microsoft C++ identifiers are
significant. Names for user-defined
types are "decorated" by the compiler
to preserve type information. The
resultant name, including the type
information, cannot be longer than
2048 characters. Factors that can
influence the length of a decorated
identifier are:
 Whether the identifier denotes
an object of user-defined type
or a type derived from a user-
defined type.
 Whether the identifier denotes
a function or a type derived
from a function.
 The number of arguments to a
function.
The dollar sign  $  is a valid identifier
character in the Microsoft C++
compiler (MSVC). MSVC also allows
you to use the actual characters
represented by the allowed ranges of
universal character names in
identifiers. To use these characters,
you must save the file by using a file
encoding codepage that includes
them.Both extended characters and
universal character names can be
used interchangeably in your code.
The range of characters allowed in an
identifier is less restrictive when
compiling C++/CLI code. Identifiers in
code compiled by using /clr should
follow.
END Microsoft Specific:
The first character of an identifier
must be an alphabetic character,
either uppercase or lowercase, or an
underscore (  _  ). Because C++
identifiers are case
sensitive,  fileName  is different
from  FileName.
Identifiers cannot be exactly the same
spelling and case as keywords.
Identifiers that contain keywords are
legal. For example,  Pint  is a legal
identifier, even though it
contains  int, which is a keyword.
Use of two sequential underscore
characters (  __  ) in an identifier, or a
single leading underscore followed by
a capital letter, is reserved for C++
implementations in all scopes. You
should avoid using one leading
underscore followed by a lowercase
letter for names with file scope
because of possible conflicts with
current or future reserved identifiers.

Types of identifiers:
There are two following types of
identifiers:
 Standard identifiers
 User defined identifiers
Standard Identifiers:
Like reserved words, standard
identifiers have special meanings in C,
but these can be redefined to use in the
program for other purposes, however
this practice is not recommended. If a
standard identifier is redefined, C no
longer remains able to use it for its
original purpose.
Examples of standard identifiers
include:
 printf
 scanf
Both of them are names of
input/output functions defined in
standard input/output library i.e.,
stdio.h.

User-defined Identifiers:
In a C program, the
programmer may need to access
memory locations for storing data and
program results. For this purpose
memory cells are named that are called
user-defined identifiers.

 C is a case sensitive language. This


means that C compiler considers
uppercase and lowercase letters to be
distinct characters.
For example:
The compiler considers SQUARE
AREA and Square Area as two
different identifiers referring to
different memory locations.

The
End

You might also like