You are on page 1of 21

Introduction to

Programming

Lesson 3

1
#include <iostream.h>
main ( )
{
cout << “ Welcome to The University of
Agricuture Peshawar“;
}

2
Variable

Variable X

3
Variable
 Pic of the memory

 25

name
 10323
of the
variable

4
Variable
Variable starts with
1. Character
2. Underscore _ (Not Recommended)

int xyz; CORRECT


int 21abc WRONG

5
Variable
 Small post box

6
Variable
Variable is the name of a location in
the memory

e.g. x= 2;

7
Variable
In a program a variable has:
1. Name
2. Type
3. Size
4. Value

8
Assignment Operator

=
x=2

X
2
9
Assignment Operator

L.H.S = R.H.S.

X+ 3 = y + 4 Wrong
Z = x +4 CORRECT
x +4 = Z Wrong
10
X = 10 ;
X 10
X = 30 ;

X 30
11
X = X + 1;

X
10 + 1
= 11
X
12
Data type
 inti ; ->
Declaration line

i
13
#include <iostream.h>
main ( )
{
int x ;
int y ;
int z ;
x = 10 ;
y = 20 ;
z=x+y;

cout << " x = " ;


cout << x ;

cout << " y = " ;


cout << y ;

cout << " z =x + y = " ;


cout << z ;
}

14
int x, y, z ;
int x; int y; int
z;
15
Data Types
1. int
2. short
3. long
4. float
5. double
6. char 16
Arithmetic operators
Plus +
Minus -
Multiply *

Divide /
Modulus %

17
Arithmetic operators

i+j
x*y
a/b
a%b
18
% = Remainder

5%2=1
2%2=0

19
4/2=2
5/2=?

20
Precedence
 Highest: ()
 Next: *,/,%
 Lowest: +,-

21

You might also like