Professional Documents
Culture Documents
in
Introduction to C++
. , ,
, .
. C++
, , , ,
.
Literals
, , ,
.
.
.
1. .
2. ,
3.
4.
.
5., ,
interger
constant . Decimal constant, Octal
constant and Hexadecimal constant
integer constant .
HSSLive.in
Non-graphic
character
operator.
Operator
.
Arithmetic
operators
, , ,
Arithmetic
operators(+,-,*,/).
Logical operator
condition
Logical operator. &&(logical AND),||(logical OR),and !
(logical NOT) Logical operator
operator(>>) extraction
get from
operator(<<) insertion put to
.
.
>> cin
<<
cout
.
variable number]
HSSLive.in
.
a=10 a 10
.
=
==
.
expression.
. C++ expression
.
Integral
expression:
.
Floating point (decimal) expression:
.
Relational expression, Logical expression:
Relational expression. condition
test expression .
assignment statements.
.
For example x=x+20; can be written as X+=20;
: x=x+20; X+=20; .
Increment and Decrement Operators
In C++ there are two special operators increment (+ C++ Increment (++), decrement (--)
+) and decrement (--) which increases the value by
one and the decrement operator decreases the .
value by one.
Control Statements
.
sequence of execution of a program. They are
.
classified into two types,
Decision statements
()
decision statement
.
.
C++ decision statement .
HSSLive.in
syntax is,
.
if(condition or expression)
if(condition or expression)
{
{
statement1;
statement1;
}
}
If the condition is true then the statement1 will be condition true
executed.
statement1
Condition
True
Statement1
False
if else statements
True False
if... else
. .
If (condition or expression)
{
statement 1;
}
else
{
statement 2;
}
True
False
Condition
Statement 1
Statement 2
else-if
ladder. .
If (test- expression )
{
Statement 1;
}
else if (test-expression)
{
Statement 2;
}
else if (test-expression)
{
Statement 3;
}
else
{
Statements;
}
HSSLive.in
{
Statement 2;
}
else if (test-expression)
{
Statement 3;
}
else
{
Statements;
}
T
T
T
Switch statement
Loops or Iterations
switch. multi- path
.
.
switch (expression)
{
case value1 :Statement 1;break;
case value2 :Statement 2;break;
case value3 :Statement 3;break;
..
..
default : Statement n;
}
expression
case .
default
.
multiple if else if
switch expression int char
.
HSSLive.in
for.
.
for(initialisation ;test expression ;updation)
{
Body of loop;
}
Initial
False
Increment
Condition
True
Body of Loop
While Statement
Condition True
False
while
.
While (expression)
{
Body of loop;
}
False
Condition
True
Body of Loop
Condition
True
False
do-while
.
do
{
Statements ;
}
While (expression);
HSSLive.in
Body of Loop
False
True
Condition
while, do-while
while
condition
do-while
condition
.
(ternary operator)
Conditional
Operator
(?:).
Jump .
C++ . break,
continue, goto and return.
HSSLive.in
False
Condition
True
Body 1
break
Body 2
continue
iteration
continue.
While, do.. while
for
update statement
.
False
Condition
True
Body 1
continue
Body 2
goto
. style .
goto label; .
Label .
Functions)
return.
Functions )