- 3

If a=10, a++=11

Need explaination in detail

7th Sep 2021, 9:18 AM
Arham Fayyaz
Arham Fayyaz - avatar
11 Answers
+ 2
What do you need help with? The syntax or the comparison
7th Sep 2021, 9:19 AM
Tim
Tim - avatar
+ 1
There’s nothing to solve, what you have stated is what would happen. If a equals 10. Then a (after, as using postfix increment) equals 11.
7th Sep 2021, 9:43 AM
DavX
DavX - avatar
+ 1
Arham Fayyaz a = 10, a++ is also 10 not 11 but after a++ , a is 11 Try this: #include <iostream> using namespace std; int main() { int a = 10; cout << a++ << endl; cout << a; return 0; } if there is pre-increment like ++a then ++a is 11, and after ++a, a will also be 11 Try this: #include <iostream> using namespace std; int main() { int a = 10; cout << ++a << endl; cout << a; return 0; }
7th Sep 2021, 12:13 PM
A͢J
A͢J - avatar
0
Please don't put tags like Pakistan
7th Sep 2021, 9:41 AM
<★Shaurya Chauhan★>
<★Shaurya Chauhan★> - avatar
0
Bro I am just having problem due to ++ what is the value or mean of plus here so
7th Sep 2021, 9:46 AM
Arham Fayyaz
Arham Fayyaz - avatar
0
Arham Fayyaz It just simply adds the value by 1
7th Sep 2021, 9:53 AM
Tim
Tim - avatar
0
Arham Fayyaz Explain what problem you are having. I have suggest possible fixes (where not using equality operator) and explained the postfix increment is increasing the value by 1. Here is a working example: #include <iostream> int main() { int a {10}; if (a == 10) a++; std::cout << a; return 0; }
7th Sep 2021, 9:56 AM
DavX
DavX - avatar
0
I think what he needs is just an explanation of what ++ does according to his question and comment 🤔
7th Sep 2021, 9:58 AM
Tim
Tim - avatar
- 1
Firstly you are using an assignment operator in a comparison statement. You would use == to check equality. Secondly you don’t assign an increment operator a value. a++ is the same as a += 1 (or a = a + 1) and doesn’t require an assignment value. Here’s an example: If (a == 10): a++ ( a now equals 11)
7th Sep 2021, 9:35 AM
DavX
DavX - avatar
- 2
Can you solve?
7th Sep 2021, 9:42 AM
Arham Fayyaz
Arham Fayyaz - avatar
- 2
Syntax
7th Sep 2021, 9:47 AM
Arham Fayyaz
Arham Fayyaz - avatar