+ 2

FUNCTIONS incrementing and decrementing

#include <iostream> using namespace std; int main() { int x = 0; if (x++) // This part of the syntax is where my question is on the if (x++) cout << "True \n"; else cout << "False\n"; return 0; } // cout False #include <iostream> using namespace std; int main() { int x = 0; if (++x) // This part lies my main question on the if(x++) cout << "True \n"; else cout << "False\n"; return 0; } // cout True My question is why does it return "True " with the plus plus/ minus minus sign on the left and return "false" when the plus plus and minus minus sign is on the right side? Anyone can help :) I have the concept for this just want some clarification from anyone.. Thanks

13th Aug 2020, 2:12 AM
Simangolwa Lifwatila
Simangolwa Lifwatila - avatar
5 ответов
+ 9
https://www.sololearn.com/learn/CPlusPlus/1610/?ref=app This will help you! In post increment, X++ will not get updated I mean incremented but it will get incremented if we use the same x further...since,u have set x=0...it will be same in the if case though u increment so,if(0) is false so it jumps to else case. But,++x will increment the value of x by 1 before it is applied to the current step
13th Aug 2020, 3:00 AM
chaithra Gowda
chaithra Gowda - avatar
+ 4
Simangolwa Lifwatila you declared x=0 initially. Case 1 : if (x++) here x value is used then incremented like if(0) then x+1.. so conditions returns false else case printed. Case 2 : if(++x) here x value incremented before check conditions that is pre-increment. Like if(1) so if case true then print true. Hope you clear 👍
13th Aug 2020, 3:23 AM
Azhagesanヾ(✿)
Azhagesanヾ(✿) - avatar
+ 3
1 and 0 have boolean counterparts in C(pp). See this, might help: https://code.sololearn.com/cn2E0C06DZdm/?ref=app
13th Aug 2020, 3:02 AM
Sandra Meyer
Sandra Meyer - avatar
13th Aug 2020, 3:14 AM
Simangolwa Lifwatila
Simangolwa Lifwatila - avatar
+ 1
I got confused without the numbers but year it's clear now thanks AZHAGESAN S
13th Aug 2020, 3:28 AM
Simangolwa Lifwatila
Simangolwa Lifwatila - avatar