β Exercise: Increment and Decrement
1. int a=5;@ProgrammingWithFaith2018
int x=++a + ++a;
cout<<x;
2. int a=5;
int b=6;
Cout<< ++a + b++;
Cout<<b;
3. int x, a, b, c;
a = 2;
b = 4;
c = 5;
x = a--+ b++ -++c;
cout<<x;
4. int x, a;
a = 2;
x = ++a *--a *++a;
cout<<x;
5. int x, a = 4;
x = ++a + ++a + ++a;
cout<<x;
β€3π₯2
β Hint:One variable can't store two value at the same time.
1.int a=5;
int x=++a + ++a;
(6+ ++a)
(7+7) because one variable can't hold two different value , (6 and 7 ) at the same time so it become 7.
7+7=14
Answer 14
2.int a=5;
int b=6;
Cout<<++a +b++// post and pre increment .
6+6 // after this line b will be 7
Cout<<++a +b++; (6+6)
=12
Cout<<b;
=7
answer=12 and 7
3.int x,a,b,c;
a=2;
b=4;
c=5;
x=a-- + b++ - ++c;
(2+4)-6
=6-6=0
cout<<x;
Answer 0
4.int x,a;
a=2
x=++a *--a* ++a
(3*2) * ++a , but one variable can't hold two values at the same time.
So, (2*2)*++a
(4*3)=12
cout<<x;// 12
Answer 12
5.int x,a=4;
x=++a + ++a + ++a;
(++a + ++a) + ++a
(5+6) + ++a but we can't store two value at one variable at the same time.
So,
(6+6)+ ++a
(12)+ 7
Answer 19
@ProgrammingWithFaith2018
β€5π₯3π1
If you ever find it difficult to understand questions and concepts like these, join our premium class. We make everything easy to understand for you.
β For registration:[ @ProgrammingWithFaith_bot ]
β For registration:[ @ProgrammingWithFaith_bot ]
β€1
π² Quiz 'C++ Chapter One'
π 16 questions Β· β± 1 min
π 16 questions Β· β± 1 min
π₯2β€1
To register for the premium class, π [@ProgrammingWithFaith_bot] π
π₯1
Do you have any questions? π€ Just ask me anonymously, and I will answer them here!π¬π
link: [ https://sma.robi.work/b/bqkJIHVlXiTl ]
link: [ https://sma.robi.work/b/bqkJIHVlXiTl ]
sma.robi.work
Send Messages Anon
A web based ngl.link alternative ask me anything platform.
β€1π1
https://movie-review-app-pi-two.vercel.app/
For more , you can join my personal channel where I share what I do. @SelfTaughtDev1
For more , you can join my personal channel where I share what I do. @SelfTaughtDev1
β€1
Do you have a Telegram channel? Are you already monetizing it? π€ Try Inside Ads β Iβve already started earning. Hereβs the link:
https://t.me/InsideAds_bot/open?startapp=r_1876122021
https://t.me/InsideAds_bot/open?startapp=r_1876122021
π₯2
β
Exercise
What is the output of this code? If there is an error, fix it and explain why it occurs.
@ProgrammingWithFaith2018
What is the output of this code? If there is an error, fix it and explain why it occurs.
#include <iostream>
using namespace std;
void add();
int main() {
int age = 21;
add();
return 0;
}
void add() {
cout << "Age: " << age << endl;
}
@ProgrammingWithFaith2018
β€2π₯°2π₯1
#include <iostream>
using namespace std;
int age = 21;
void add() {
cout << "Age: " << age << endl;
}
int main() {
add();
return 0;
}
Error: variable age is not local to the function β οΈ
This one is also possible β
#include <iostream>
using namespace std;
int age = 21;
void add();
int main() {
add();
return 0;
}
void add() {
cout << "Age: " << age << endl;
}
Output: 21 π
@ProgrammingWithFaith2018
β€2π₯°2
To register for the premium class, π [@ProgrammingWithFaith_bot] π
β€2