2-Introduction To Programming - Lectuer1 DR Albert - Part 2
2-Introduction To Programming - Lectuer1 DR Albert - Part 2
Lesson 2.3
Constants
• Declaration:
+=,-=,*=,/=,%=,>>=,<<=,&=,|=,and ^=
Examples
Given:
int x=5,y=6,z=9,m;
float w=3.4 , k=4;
So.,
m=y/2; means m=3
m=x/2; means m=
m=5%2; means m=
m=6%2; means m=
m=7%2; means m=
M =W%2; means m= error
Postfix and Prefix Assignment
i++
++i
i--
--i
i++
first provides the value of i to
then adds I to i, while
++i
does the addition first
What is the output? What is the output?
Int x =5;
Int x =5; Cout<<“x=“<<++x<<endl;
Cout <<“x=“<<x++<<endl; X+=10;
Cout<<x;
X+=10;
Cout<<x; Solution
X=6
Solution 16
X=5
16
What is the output?
Int x =5,y=3,z=7;
z=z/2+ ++y*x--;
Cout <<“x=“<<x<<endl;
Cout <<“y=“<<y<<endl;
Cout <<“z=“<<z<<endl;
Solution
X=
Y=
Z=
What is the output? Z= z/2+ ++y *x--;
Int x =5,y=3,z=7;
variable= z/2+ ++y *x--;
Z=z/2+ ++y*x--;
variable=7/2 +
Cout <<“x=“<<x<<endl;
variable=7/2 + 4*
Cout <<“y=“<<y<<endl;
variable=7/2 + 4*5
Cout <<“z=“<<z<<endl;
X- - Screen
Memory X=4
Solution
X=5 ->4
X= Y=4
Y=3 ->4
Y=
Z=7 ->23 Z=23
Z=
TRY
int x=5,y,z;
y=x%3;
z=x+y%--y;
cout<<++x<<endl;
cout<<y++<<endl;
cout<<++z<<endl;
x+=y++*2;
z=x+y;
cout<<++x<<endl;
cout<<++y<<endl;
cout<<z++<<endl;
system("pause");
}