Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

statement

expression

statement ) (

expression

....... :

)
(....... :

; cout << x

12+14
;A=A+1

)while (true

Statement

hello world

{
;"cout << "222
}

A+ b / c
138
) ) sin( x+3 )* f( g( y

expressions
expression
literal

15
hello world
183

assignment
expression

B=5

variable

A= B = 5

) B 5
A 5 (B
expression

function

;) ) cout << sin( cos( x

Declarations & Definitions


declaration

function
Greeting
.......

; )( void Greeting
)( void main

main
.......

{
;)(Greeting
}

.....
main

)( void Greeting
{
;cout << yahla
}

Booleans & Conditions


++c data type bool ) true: ( false
) (.
operators == .... != , < , > , true false

bool C++
.

ASCII

!! q

)if (true
{
....
}
}while(15) {....
)'if ('q
{
....
}


)if (0
{
.....
}
}while ( false ) {....
}if (48-48) {....

If
if statement

if expression
x=a ? b : c ;
?
: c b

Max = (a>b) ? a : b ;

if ( choice==5)
{
cout << the result is <<x ;
}
if ( done )

cout << (y==0) ? zero : nonzero ;

return 0 ;
if (a==b)

cout << y ? zero : nonzero ;

{cout << theyre equal ;}


else{ cout << they arent equal ;}

While loops
1.

Condition 0
false

)( while


while
.2 condition
:


09

;int x = 0
) while ( x < 10
; {cout <<x
; x++
}


function test

) )(while ( test
} ;) ({ DoJob

. while
) ( 1

condition
.


code
statement

!!! code
while !

) while( A>B
B++

; )while ( x<10
;x++

for loops
) ; ; ( for

.1 for .

) ; ; ( for

code

infinite loop

;cout <<hi
}

;)for (int i=0; i<10 ; i++


code loop

.2 for

while
:

)for ( ; ;
}{code

;
) while(

{
code

)for (int i= 0; i<10; i++


0

10

) (

;cout << i

)for (int i=10; i>= 1; i++


;cout << i

)for ( Node * n=lst -> head; n!=Null; n=n -> next


{

Linked list

;cout << n -> value


}

statements
statement

;cout << 5

} ;{ int x= 5, y = 6


Control flow

or

{
}

while , if , for

while , if , for statement :


)for( int i = 0; i < 10; i++
statement

statement
.

)if( i % j
) )( while( checking
;)(dojob

for if if while
while statement) .( function

if
statement
if

)if (x > 9
;cout << x
)if (x > 5

statement

else
statement

else
};{x++; y--

Arrays

array

]arr [5

[ index

]v [i

expression

] )( homes [ get_names


) ... long , int( ]

; ]int a1 [100

.....

;]cout << a [i

.. names [5]= samy; .....


........ .

;Frequency [x] ++

functions
Function

function definition

function application
function

)int add (int x, int y


{
;return x + y
}
)(void main
{
;)cout << add(18, 46
;"cout << " GOOD BYE
}

add main

function function return


function function

Parameters
y x formal parameters
function

actual parameters
expressions
function
) 18 20 (

)int add( int x, int y


{
;return x + y
}
)(void main
{
;int x = 10
;)cout<< add(18 , x +10
}

arguments function
formal parameters
function parameters

) (DoStuff( ) , f

Return values
return values function add
add

return values
function return value
function application
expression
: expression
;)int x = add(a, b

index
array

a[ get_position() ] = 12

return

function

function

) )f( g(X
parameter
function

function

return value
) (

)int sign_of( int value


{
)if (value == 0
;return 0
)if ( value>0
;return 1
)if ( value<0
;return -1
}


else return
function

return values
function void
expression
return value



bugs

)(void f
{
.............
}
)(void main
{
;)(cout<< f
}

function
)int sign_of( int value
{
)if (value == 0
;return 0
)if (value>0
;return 1
)if (value<0
;return -1
}

if

return -1

You might also like