Date post: | 20-Jan-2018 |
Category: |
Documents |
Upload: | edwin-bradley |
View: | 231 times |
Download: | 0 times |
Introduction to Introduction to ProgrammingProgramming
Lesson 3Lesson 3
#include <iostream.h>#include <iostream.h>main ( )main ( ){{
cout << “ Welcome to Virtual University cout << “ Welcome to Virtual University “;“;
}}
VariableVariable
VariableVariable X
VariableVariable Pic of the memoryPic of the memory
2525
1032310323
namenameof the of the variablvariablee
VariableVariableVariable starts withVariable starts with
1.1. CharacterCharacter2.2. Underscore _ Underscore _ (Not (Not
Recommended)Recommended)
VariableVariable Small post boxSmall post box
X
VariableVariableVariable is the name of a Variable is the name of a
location inlocation inthe memorythe memory
e.g. x= 2;e.g. x= 2;
VariableVariableIn a program a variable In a program a variable
has:has:1.1. NameName2.2. TypeType3.3. SizeSize4.4. ValueValue
Assignment Assignment OperatorOperator
==x = 2x = 2
X 2
Assignment Assignment Operator Operator
L.H.S = R.H.S.L.H.S = R.H.S.
X+ 3 = y + 4 X+ 3 = y + 4 WrongWrongZ = x +4Z = x +4x +4 = Z x +4 = Z WrongWrong
X = 10 ; X = 10 ;
X = 30 ;X = 30 ;
X 10
X 30
X = X + 1;X = X + 1;X 10 + 1
= X
11
Data typeData type int i ; -> int i ; ->
Declaration lineDeclaration line
ii
#include <iostream.h>#include <iostream.h>main ( )main ( ){{
int x ;int x ;int y ;int y ;int z ;int z ;x = 10 ;x = 10 ;y = 20 ;y = 20 ;z = x + y ;z = x + y ;
cout << " x = " ;cout << " x = " ;cout << x ;cout << x ;
cout << " y = " ;cout << " y = " ;cout << y ;cout << y ;
cout << " z =x + y = " ;cout << " z =x + y = " ;cout << z ;cout << z ;
}}
int x, y, z ;int x, y, z ;int x; int y; int z int x; int y; int z
;;
Data TypesData Types1.1. intint2.2. shortshort3.3. longlong4.4. floatfloat5.5. doubledouble6.6. charchar
Arithmetic Arithmetic operatorsoperators
PlusPlus ++MinusMinus --MultiplyMultiply **
DivideDivide / / ModulusModulus %%
Arithmetic Arithmetic operatorsoperators
i + ji + jx * yx * ya / ba / ba % ba % b
% = Remainder% = Remainder
5 % 2 = 15 % 2 = 12 % 2 = 02 % 2 = 0
4 / 2 = 24 / 2 = 25 / 2 = ?5 / 2 = ?
PrecedencePrecedence Highest:Highest: ( )( ) Next:Next: * , / , %* , / , % Lowest:Lowest: + , -+ , -