The Basics of C++: Syntax
The Basics of C++: Syntax
Syntax
Data Types
A word on characters
http://www.asciitable.com/
A word on characters
Loops
Loops
Incrementing and
Decrementing Variables
i++
i++ is
is equivalent
equivalent to
to i=i+1
i=i+1
i-i-- is
is equivalent
equivalent to
to i=i-1
i=i-1
i+=5
i+=5 is
is equivalent
equivalent to
to i=i+5
i=i+5
i-=2
i-=2 is
is equivalent
equivalent to
to i=i-2
i=i-2
If then
if(some condition)
{
Do something
Conditional Statements
10
If thenelse
if(some condition)
{
Do something
}
else
{
Do something else
Conditional Statements
11
If thenelse
if(some condition)
{
Do something
}
else if(some other condition)
{
Do something else
Conditional Statements
12
&&: and
||: or
==: equal to
!=: not equal to
>: greater than
<: less than
>=: greater than or equal to
<=: less than or equal to
Conditional Operators
13
if(x==3)
{
if(x==3)
{
do something
}
if(x==4)
{
do something
do something
}
else if(x==4)
{
do something
Conditional Statements
14
Conditional Statements
15
or
A Word on Braces
16
The semicolon
17
1
2
3
4
5
6
7
8
9
10
x=3
y=2
if(x==3)
{
y++
}
else
{
y=y-1
}
18
A Comment on Comments
19
20
int main ()
{
int i, j;
i=3;
j=i++;
return j;
Function name
Data type to be returned
Parameter list
-This function does not have any parameters.
Return statement
Function Format
21
22
Parameter list
There are two parameters of type int.
Function Format
23
int main()
{
int i, j;
i=3;
j=i++;
return j;
A Sample Program