You are on page 1of 20

COMPUTER SCIENCE NOTES FOR FIRST PUC

CHAPTER 07: INTRODUCTION TO C++.


1. HISTORY OF C++.
 “C++ is a middle-level programming language developed by Bjarne Stroustrup s
in early 1980 at Bell Labs. C++ runs on a variety of platforms, such as
Windows, Mac OS, and the various versions of UNIX.”
 C++ is a compiled, general-purpose, case-sensitive, free-form programming
language that supports procedural, object-oriented, and generic programming.
 C++ is regarded as a middle-level language, as it comprises a combination of
both high-level and low-level language features.
 “C++ was developed by Bjarne Stroustrup starting in early 1980 at Bell Labs in
Murray Hill, New Jersey, as an enhancement to the C language and originally
named C with Classes but later it was renamed C++ in 1983.”
 C++ is a superset of C, and that virtually any legal C program is a legal C++
program
 The ANSI/ISO C++ committee was finally responsible for standardizing the
features (ANSI America National Standards Institute, ISO International Standard
Organization).
 The addition of new features has transformed C from a language that currently
facilitates top-down structured design to one that provides bottom-up object-
oriented design

2. CHARACTERISTICS OF C++.
 C++ have some of the major characteristics over other languages
namely
 OBJECT-ORIENTED PROGRAMMING: The possibility to orient programming to
objects allows the programmer to design applications from a point of view more
like a communication between objects rather than on a structured sequence of
code. In addition it allows a greater reusability of code in a more logical and
productive way.
 PORTABILITY: We can practically compile the same C++ code in almost any
type of computer and operating system without any modification. C++ is most
used and ported programming language in the world.
 MODULAR PROGRAMMING: An application’s body in C++ can be made up of
several source code files that are compiled separately and then linked together.
 C COMPATIBILITY: C++ offer back ward compatible with C language, any
code can be written in C can easily be included in a C++ program without any
changes.
 SPEED: The resulting code from a C++ Compilation is very efficient, due indeed
to its duality as high-level and low level language and to the reduced size of the
language itself.
 MACHINE INDEPENDENT: It is a Machine Independent Language, Thus
programming is easy. It can be used in different type of machine. (Machine
independent: A term applied to software that is not dependent on the properties
of a particular machine, and can therefore be used on any machine.)
 FLEXIBILITY: It is highly flexible language with Versatility.

PREPARED BY, MR. MOHIDDIN SAHEB, LECTURER. PAGE 1


DEPARTMENT OF COMP.SCIENCE, ST.JOSEPH’S PU COLLEGE, BENGALURU-25
COMPUTER SCIENCE NOTES FOR FIRST PUC
 WIDE RANGE OF LIBRARY FUNCTIONS: It has huge Library Functions which
in turn reduces the code development time and also reduces cost of software
development.
 SYSTEM SOFTWARE DEVELOPMENT: It can be used for developing System
Software viz., operating systems, compilers, editors and data bases.

3. C++ CHARACTER SET.


 Character set of any programming language identifies the elements which can
be used in the language to construct the various statements and the structure of
a language.
 Character set for C++ includes the below

CHARACTER DESCRIPTION
ALPHABETS Upper case and lower case (A a – z Z).
DIGITS Digits ranging from 0 to 9
SPECIAL CHARACTER + - = < > ! ~ : ? { } ( ) [ ] & % . # ; blank and many more

WHITE SPACE Blank space, Horizontal tab, Carriage return, New line, Form
feed

4. C++ TOKENS.
 “A token is a smallest individual unit of a program.”
 C++ consists of six tokens which are as follows namely
 Keywords.
 Identifiers.
 Literals or Constants.
 Operators.
 Punctuations.

KEYWORDS.
 Some of the words are used in C++ program that have standard predefined
meanings which are nothing but keywords.
 “Keywords are predefined reserved words which has a special meaning
to compiler.”
 Commonly used keywords are as follows
auto break case catch class
const continue default delete do
double enum else extern float
For friend goto if inline
Int long new operate private
public protected static size switch
template this throw try typdef
union voliate void virtual while

PREPARED BY, MR. MOHIDDIN SAHEB, LECTURER. PAGE 2


DEPARTMENT OF COMP.SCIENCE, ST.JOSEPH’S PU COLLEGE, BENGALURU-25
COMPUTER SCIENCE NOTES FOR FIRST PUC
IDENTIFIERS
 “Identifier refers to a name of program elements such as variables,
functions and arrays.”
 Some of the rules that should be used for identifiers are as follows:
 Identifiers are sequence of character chosen from the set A-Z, a-z, 0-9 and
_ (underscore)
 C++ is a case sensitive so that HELLO and hello are treated as two different
identifiers.
 First character of an identifiers should always start with an alphabets or an
underscore which be followed by either alphabets or certain symbol.
 Special character or symbol except underscore (_) should not be used in
identifiers.
 It should be a single words.
 Reserved words should not be used as identifiers.

VALID IDENTIFIERS ARE


Sum, avg_num, PINCODE, largestnumber

INVALID IDENTIFIERS ARE


!HAI, 15sum, 10th, largest number, __SUM

CONSTANTS OR LITERALS
 Constant is a fixed value that does not change during the execution of the
program.
 Different constant are as follows.

CONSTANTS

Numeric Constants Character Constants

Integer Constants Real Constants Single Character String


Constants Constants

Decimal Octal

Hexadecimal

PREPARED BY, MR. MOHIDDIN SAHEB, LECTURER. PAGE 3


DEPARTMENT OF COMP.SCIENCE, ST.JOSEPH’S PU COLLEGE, BENGALURU-25
COMPUTER SCIENCE NOTES FOR FIRST PUC
NUMERIC CONSTANTS: Numeric constants are the constants that contains
numerals. It may also have a leading sign and decimal point.
INTEGER CONSTANTS
 An integer constant refers to a sequence of digits. (0-9) and does not have
decimal point is called integer constants.
 There are the following three types of integer constants:
 Decimal Constants: It contains digits between 0 to 9. For example,
898, 67, 66.
 Octal Constants: It contains digits between 0 to 7 and must begin with
0. For example, 012, 032, 067.
 Hexadecimal Constants: It contains digits between 0 to 9 and letters
a to f (either in upper or lower case). It must begin with 0X or 0x. For
example, 0x23, 0x76, 0X6A, 0XFF.

REAL OR FLOATING-POINT CONSTANTS


 Integer numbers are inadequate to represent quantities that vary continuously,
such as distances, heights, temperatures, prices and so on. These quantities are
represented by numbers containing fractional parts like 23.78. Such numbers
are called floating-point constants or real constants.
 These values contain decimal points (.) and can contain exponents. They are
used to represent values that will have a fractional part and can be represented
in two forms (i.e., fractional form and exponent form).
 Floating-point constants have
 Mantissa: which specifies the value of the number.
 Exponent: which specifies the magnitude of the number.
 The exponent notation the ‘e’ or ‘E’ symbol is used to separate the mantissa and
exponent. Example: 0.000029 = 2.9*10-5 = 2.9e-5 decimal point shifted to
right

CHARACTER CONSTANTS:
SINGLE CHARACTER CONSTANTS
 “A character constant contains a single character enclosed within a pair of single
quote marks.”
 Examples of character constants are: ‘5’ ‘X’ ‘;’ ‘‘
 Note that the character constant ‘5’ is not the same as the number 5. The last
constant is a blank space. Character constants have integer values known as
ASCII values.
 It is also possible to perform arithmetic operations on character constants.

STRING CONSTANTS
 “A string constant is a sequence of characters enclosed in double quotes.”
 By default the compiler adds a special character called the ‘null character’ (‘\0’)
at the end of the string to mark the end of the string.
 For example, the string literal has to be represented as
char str[15] =”Computer Science”;
 This is actually represented as char str[15] =”Computer Science \0" in the
memory.

PREPARED BY, MR. MOHIDDIN SAHEB, LECTURER. PAGE 4


DEPARTMENT OF COMP.SCIENCE, ST.JOSEPH’S PU COLLEGE, BENGALURU-25
COMPUTER SCIENCE NOTES FOR FIRST PUC
NOTE
Uppercase character (A-Z) ASCII value is – 65 TO 90
Lowercase character (a-z) ASCII value is – 97 to 122
Digits (0-9) ASCII value is – 48 to 57

ESCAPE SEQUENCE
 C++ supports some special backslash character constants that are used in
output functions. For example, the symbol ‘\n’ stands for new line character.
 Escape sequence is special string used to control output on the monitor
and they are represented by a single character.
 Each one of them represents one character, although they consist of two
characters. These character combinations are called escape sequences.
 Some of the Backslash Character Constant
ESCAPE SEQUENCE MEANING
‘\a’ audible alert(bell)
‘\b’ back space
‘\f’ form feed
‘\n’ new line character
‘\r’ carriage return
‘\t’ horizontal tab
‘\v’ vertical tab
‘\’’ single quote
‘ \” ’ double quote
‘\?’ question mark
‘\\’ backslash mark
‘\0’ null character

PUNCTUATIONS.
 Punctuators in C++ have syntactic and semantic meaning to the compiler but do
not by themselves specify an operation that yields a value. Some punctuators
can be either alone or in combination, and they can be significant to the
preprocessor. The following characters are considered as punctuators:
 Brackets [] used in arrays for single, two and multidimensional.
 Parenthesis () used to enclose expression or an arguments to a function.
 Braces {} used to identify the start and end of a block for a statement.
 Comma, Semicolon; symbol that can be used as terminators.
 Colon: used to provide a label for a statement.

5. OPERATOR.
 C++ supports a rich set of built-in operators and there are almost 45 different
operators.
 “An Operator is a symbol that tells the computer to perform certain
mathematical or logical manipulations.”

PREPARED BY, MR. MOHIDDIN SAHEB, LECTURER. PAGE 5


DEPARTMENT OF COMP.SCIENCE, ST.JOSEPH’S PU COLLEGE, BENGALURU-25
COMPUTER SCIENCE NOTES FOR FIRST PUC
 Operators are used in programs to manipulate data and variables.
 Operator operates on constants and variables which are called operands.
Operators may also be classified on the number of operands they act on either:
 Operator can be either ‘unary’ or ‘binary’ or ‘ternary’ operators.
OPERATOR DESCRIPTION
Unary operator These operator operates on a single operand.
Example: ++,--,!,~
Binary operator These operator operates on a two operand.
Example: +,-,<,>,<=,>=
Ternary operator OR Conditional Operator The ternary operator operates on three operands.
Example: ?:

 C++ operators can be classified into a number of categories. They are:


 Arithmetic operators.
 Relational Operators.
 Logical Operators.
 Assignment Operators.
 Increment and Decrement Operators.
 Conditional Operators.
 Bitwise Operators.
 Special Operators.

ARITHMETIC OPERATORS:
 Arithmetic operators include +, -, *, /, %, which performs all mathematical
manipulations.
 These operators can operate on any built-in data type allowed in C++.
 Table shows the function of Arithmetic Operators.
OPERATORS MEANING
+ Addition or unary plus
- Subtraction of unary minus
* Multiplication
/ Division
% Modulo Division

 Integer division truncates any fractional part.


 The modulus division produces the remainder of an integer division.
 The modulus division operator % cannot be used on floating point data.
 Assume variable A holds 10 and variable B holds 20, then:

PREPARED BY, MR. MOHIDDIN SAHEB, LECTURER. PAGE 6


DEPARTMENT OF COMP.SCIENCE, ST.JOSEPH’S PU COLLEGE, BENGALURU-25
COMPUTER SCIENCE NOTES FOR FIRST PUC

RELATIONAL OPERATORS:
 Relational operators are used to compare two operands, and depending on their
relation, certain decisions are taken.
 For example, it can be used to compare the age of two persons, price of two items and
so on. There are 6 types of relational operators. They are:
OPERATOR MEANING
< Is less than
> Is greater than
<= Is less than or equal to
>= Is greater than or equal to
== Is equal to
!= Is not equal to
 A simple relational expression contains only one relational operator and takes the
following form:

(Operand 1) Relational operator (Operand 2)

 Assume variable A holds 10 and variable B holds 20, then

LOGICAL OPERATORS:
 C++ supports three Logical Operators. They are:

OPERATOR MEANING
&& Logical AND
|| Logical OR
! Logical NOT

PREPARED BY, MR. MOHIDDIN SAHEB, LECTURER. PAGE 7


DEPARTMENT OF COMP.SCIENCE, ST.JOSEPH’S PU COLLEGE, BENGALURU-25
COMPUTER SCIENCE NOTES FOR FIRST PUC
 The logical operators && and || are used when we want to test more than one
condition and make decisions. Example: a>b && x == 10
 An expression of this kind which combines two or more relational expression is
termed as a logical expression or a compound relational expression.
 Like the simple relational expressions, a logical expression also yields a value of one
or zero, according to the truth table shown below. The logical expression given above
is true only if a>b is true and x==10 is true. If either (or both) of them are false, the
expression is false.
(Operand 1) logical operator (Operand 2)

TRUTH TABLE
OP-1 OP-2 VALUE OF THE EXPRESSION
Op-1 && op-2 op-1 || op-2
0 0 0 0
0 1 0 1
1 0 0 1
1 1 1 1

 Assume variable A holds 0 and variable B holds 1, then

ASSIGNMENT OPERATORS:
 Assignment operators are used to assign the result of an expression to a variable.
Usually, ‘=’ operator is used. There is an additional ‘shorthand’ assignment operators
of the form
V op = exp;
V= variable
exp = expression and
op = a binary arithmetic operator.

 The Operator op= is known as the shorthand assignment operator. The assignment
statement
v op = exp;
is equivalent to :
v = v op (exp);

PREPARED BY, MR. MOHIDDIN SAHEB, LECTURER. PAGE 8


DEPARTMENT OF COMP.SCIENCE, ST.JOSEPH’S PU COLLEGE, BENGALURU-25
COMPUTER SCIENCE NOTES FOR FIRST PUC

SHORTHAND ASSIGNMENT OPERATORS

 The advantages of using shorthand assignment operators are:


 The statement is more concise and easier to read.
 What appears on the left-hand side need not be repeated and therefore it becomes
easier to write.
 The statement is more efficient.

INCREMENT AND DECREMENT OPERATORS:

INCREMENT OPERATOR
 This is used to increment the value of a variable in an expression.
 Increment operator is denoted by ++.
 They can occur in either prefix or postfix position, with possibly different effects
occurring.
There are two types of increment operator.
PRE INCREMENT OPERATOR:
 Pre increment operator is used to increment the value of variable before using
expression.
 The general syntax is: ++variable

PREPARED BY, MR. MOHIDDIN SAHEB, LECTURER. PAGE 9


DEPARTMENT OF COMP.SCIENCE, ST.JOSEPH’S PU COLLEGE, BENGALURU-25
COMPUTER SCIENCE NOTES FOR FIRST PUC
 In pre increment operator there are two steps namely
 Increment the value of variable.
 New value is assigned.
++a
Here a=a+1
a=New value
 Example: a=5;
n=++a; In this case, the value of a would be 5 and n would be 6 because
value of a gets modified before using the expression.

POST INCREMENT OPERATOR:


 The value is first used inside the expression and then increment.
 The general syntax is: variable++
 In post increment operator there are two steps namely
 Value is assigned to a variable.
 Increment the value of variable.
a++
Here a= Old value.
a= a+1
 Example: a=20;
y=a++; In this case, the value of a would be 20 and y would be 21 because
value of a gets modified after using the expression.

DECREMENT OPERATOR
 This is used to decrement the value of variable in an expression.
 Decrement operator is denoted by --.
 They can occur in either prefix or postfix position, with possibly different effects
occurring.
 There are two types of decrement operator
PRE DECREMENT OPERATOR:
 Value is first decremented and the used inside the expression.
 The general syntax is: --variable
 In pre decrement operator there are two steps namely
 Value is decrement.
 New value is assign.
a--
Here a= a-1
a= New value
 Example: a=5;
b=--a
a=a-1
=5-1
a=4
POST DECREMENT OPERATOR:
 Value is first used inside the expression and then decrement.
 The general syntax is: variable--
 In pre decrement operator there are two steps namely
 Value is assigned to a variable.
 Value is decrement.
--a
Here a= Old Value
a= a-1
 Example: a=9;

PREPARED BY, MR. MOHIDDIN SAHEB, LECTURER. PAGE 10


DEPARTMENT OF COMP.SCIENCE, ST.JOSEPH’S PU COLLEGE, BENGALURU-25
COMPUTER SCIENCE NOTES FOR FIRST PUC
b=--a
a=9-1
=9-1
a=8

NOTE:
Post Increment (i++): Current value of ‘i’ is used and then it is incremented by 1.
Pre Increment (++i): First ‘i’ is incremented by 1 and then its value is used.
Post Decrement (i--): Current value of ‘i’ is used and then it is decremented by 1.
Pre Decrement (--i): First ‘i’ is decremented by 1 and then its value is used.

EXAMPLE:

i = 11;
i = i++ + ++i;
i = i++ + ++i
i = (i is used before increment) + (i is used after increment)
i = 11(i=12) + 13(i=13)
i = 11 + 13
i= 24

int a=11, b=22, c;


c = a + b + a++ + b++ + ++a + ++b;
c = a + b + a++ + b++ + ++a + ++b
c = 11 + 22 + (a is used before increment) + (b is used before increment) + (a is
used after increment) + (b is used after increment)
c = 11 + 22 + 11(a=12, b=22) + 22(a=12, b=23) + 13(a=13, b=23) + 24(a=13,
b=24)
c = 11 +22 + 11 + 22 + 13 + 24
c= 103

PREPARED BY, MR. MOHIDDIN SAHEB, LECTURER. PAGE 11


DEPARTMENT OF COMP.SCIENCE, ST.JOSEPH’S PU COLLEGE, BENGALURU-25
COMPUTER SCIENCE NOTES FOR FIRST PUC

CONDITIONAL OPERATOR OR TERNARY OPERATOR:


 C++ consists of a very special operator known as ternary or conditional operator
and is represented by ? :
 SYNTAX: Exp1 (Condition)? Exp2: Exp3 where Exp1, Exp2 and Exp3 are
expressions

Working of Conditional/Ternary Operator


Step 1: Expression1 is the condition to be evaluated.
Step 2A: If the condition (Expression1) is true then Expression2 will be
executed.
Step 2B: If the condition (Expression1) is false then Expression3 will be
executed.
Step 3: Results will be returned.

PREPARED BY, MR. MOHIDDIN SAHEB, LECTURER. PAGE 12


DEPARTMENT OF COMP.SCIENCE, ST.JOSEPH’S PU COLLEGE, BENGALURU-25
COMPUTER SCIENCE NOTES FOR FIRST PUC
BITWISE OPERATORS:
 Bitwise operators are special operators that are used for manipulation of data
at the bit level.
 These operators are used for testing the bits, or shifting them to right or left.
Bitwise operators may not be applied to float or double.

OPERATOR MEANING
& Bitwise AND
| Bitwise OR
^ Bitwise exclusive OR
<< Left Shift
>> Right Shift
~ One’s Complement

OPERATOR MEANING TRUTH TABLE EXAMPLE


Bitwise AND This operator will return
a '1-bit' if both bits are 1010
equal to '1', otherwise it 0110
will return 0. 0010

Bitwise OR This operator will return 1010


a '1-bit' if either bit is 0110
equal to '1', otherwise it 1110
will return 0.

Bitwise This operator will return 1010


exclusive OR a '1-bit' if one bit is '0' 0110
and the other bit is '1' 1100
(i.e.: both operands are
different), otherwise it
will return 0.

One’s This operator will If value is 1 then 1’s is 0. 1010


Complement reverse the bit values If value is 0 then 1’s is 1. 1’s is 0101

PREPARED BY, MR. MOHIDDIN SAHEB, LECTURER. PAGE 13


DEPARTMENT OF COMP.SCIENCE, ST.JOSEPH’S PU COLLEGE, BENGALURU-25
COMPUTER SCIENCE NOTES FOR FIRST PUC

Right Shift It is denoted by >> 110011110


Bit pattern of data can be shifted by specified number Num>>1 which
of position to right. yields
When data are shifted right leading zeros are filled 011001111
with zero. Num>>5 which
SYNTAX: [variable]>>[number of place] yields
000001100
Left Shift It is denoted by << 11010111
Bit pattern of data can be shifted by specified number Num<<
of position to left. 1 which yields
When data are shifted left trailing zeros are filled with 10101110
zero. Num<<5 which
SYNTAX: [variable]<<[number of place] yields
11100000

PREPARED BY, MR. MOHIDDIN SAHEB, LECTURER. PAGE 14


DEPARTMENT OF COMP.SCIENCE, ST.JOSEPH’S PU COLLEGE, BENGALURU-25
COMPUTER SCIENCE NOTES FOR FIRST PUC

SPECIAL OPERATORS: The other operators supported by C++ are

7. ARITHMETIC EXPRESSIONS
 An expression is a combination of operators, constants and variables.
 An expression may consist of one or more operands, and zero or more
operators to produce a value.
 Operand may be variables, constant or expressions.

There are 3 arithmetic expression


 Integer mode expression: When both the operands in an expression are
integers, then the expression is called an integer expression, and the
operation is called integer arithmetic. It always result an integer value.
Example: a=5, b=5 then a*b=25, a/b=1 , a+b=10 , a-b=0
 Real mode expression: An arithmetic operation involving only real or
floating point operands is called real arithmetic, it always result an floating
value. Example: a=10.0 , b=5.0 are float ,then a*b=50.0 a/b=2.0 a+b=15.0
a-b=5.0
 Mixed mode expression: This is a combination of integer and float
arithmetic, where one of the operands in real and the other is integer. This
type of expression is called a mixed-mode arithmetic expression.
Example: Let a=13, b=2.6, then a / b = 13 / 2.6 = 4.9056 15/10.0=1.5

PREPARED BY, MR. MOHIDDIN SAHEB, LECTURER. PAGE 15


DEPARTMENT OF COMP.SCIENCE, ST.JOSEPH’S PU COLLEGE, BENGALURU-25
COMPUTER SCIENCE NOTES FOR FIRST PUC
EVALUATION OF EXPRESSIONS
 To evaluate an expression, the given algebraic expression must be converted
to a C++ expression.
 Then it must be written in the form of assignment statement.
 All the variables on the right hand side must be assigned values before
evaluation.

PRECEDENCE OF ARITHMETIC OPERATORS


 Any arithmetic expression is evaluated according to the rule of precedence of
operators.
 Example: 4*5/2 Evaluation takes place from left to right i.e., First 4 is
multiplied by 5 and the result 20 is divided by 2.

PREPARED BY, MR. MOHIDDIN SAHEB, LECTURER. PAGE 16


DEPARTMENT OF COMP.SCIENCE, ST.JOSEPH’S PU COLLEGE, BENGALURU-25
COMPUTER SCIENCE NOTES FOR FIRST PUC

PREPARED BY, MR. MOHIDDIN SAHEB, LECTURER. PAGE 17


DEPARTMENT OF COMP.SCIENCE, ST.JOSEPH’S PU COLLEGE, BENGALURU-25
COMPUTER SCIENCE NOTES FOR FIRST PUC

8. STRUCTURE OF A C++ PROGRAM

DOCUMENTATION SECTION OR COMMENTS:


 This section allows us to write comments about a statement or the program as a whole.
Single line comments begin with two slash signs (//) and they are not executed by the
compiler. E.g. //Program to find area of a circle//
 Multiline comments can be enclosed between /* and */
LINK SECTION:
 Lines beginning with a hash sign (#) are directives for the preprocessor. They are
processed first by the compiler before the compilation of other statements
 The directive #include <iostream.h> and #include<conio.h> tells the preprocessor to
include the specified header files that includes the declarations of the library functions
inC++
DEFINITION SECTION:
 Symbolic constants are defined here. E.g. #define PI 3.14159 is a symbolic constant
whose name is replaced by its value wherever it is referred to in the program
GLOBAL DECLARATION SECTION:
 This section contains the declaration of global variables whose scope remains throughout
the entire program and can be used by all functions in the program
void main ():
 The main function is the point where all C++ programs start their execution,
independently of its location within the source code. It is essential that all C++
programshave a main function.

PREPARED BY, MR. MOHIDDIN SAHEB, LECTURER. PAGE 18


DEPARTMENT OF COMP.SCIENCE, ST.JOSEPH’S PU COLLEGE, BENGALURU-25
COMPUTER SCIENCE NOTES FOR FIRST PUC
 We can find the body of the main function enclosed in braces ({}) below this line.
DECLARATION PART:
 Contains the declaration of local variables whose scope remains till the end of the
function. E.g. float r, area;
EXECUTABLE PART:
 C++ statements are written in this part. Statements can be expressions, input-
outputfunctions, conditional statements, looping statements, function call and so on.
 Semicolon character (;) is used to mark the end of the statement and in fact it must
beincluded at the end of all expression statements in all C++ programs
 E.g. area=PI*r*r;
SUBPROGRAM SECTION:
 Contains the definitions of all user-defined functions

IMPORTANCES OF <iostream.h>
 Declares objects that control reading from and writing to the standard streams.
 This is often the only header you need to include to perform input and output
 Include statement tells compiler to include Standard Input Output Stream inside C++
program.
 This header is provided to user along with the compiler.

COMMENTS IN C++
 Program comments are explanatory statements that you can include in the C++ code
that you write and helps anyone reading its source code.
 All programming languages allow for some form of comments.
 Comment is ignored by Compiler.
 Comment are written for user understanding.
 All characters available inside any comment are ignored by C++ compiler.

PREPARED BY, MR. MOHIDDIN SAHEB, LECTURER. PAGE 19


DEPARTMENT OF COMP.SCIENCE, ST.JOSEPH’S PU COLLEGE, BENGALURU-25
COMPUTER SCIENCE NOTES FOR FIRST PUC
 C++ supports single-line and multi-line comments.
 Single Line Comments in C++
 Single Line comment starts with “//” symbol.
 Remaining line after “//” symbol is ignored by browser.
 End of Line is considered as End of the comment
 Multi Line Comments in C++
 Consider the below example

 Multi Line comment starts with “/*” and ends with “*/” symbol.

USES OF COMMENTS.
 Comments are non-Executable Statements.
 Comments are always neglected by compiler.
 Comments are replaced by white spaces during the preprocessor phase.
 Comments can be written anywhere and any number of times.
 Comments can be used for documentation.
 Comments can be Single Line or multiple line.

PREPARED BY, MR. MOHIDDIN SAHEB, LECTURER. PAGE 20


DEPARTMENT OF COMP.SCIENCE, ST.JOSEPH’S PU COLLEGE, BENGALURU-25

You might also like