if (x) means???

#include<iostream.h>
int main()
{
int x=0,y=0,z=0;
if (x)
{
x--;
y=x+2;
cout<<x--<<endl;
cout<<y;
}
else cout<<x++;
return 0;
}

what does if(x) mean here?
closed account (Dy7SLyTq)
c style version of bool ie false is < 1 and true > 0
if ( x )

is equivalent to

if ( x != 0 )

Vlad is correct and DTSCode is not correct.

In C and C++, zero is false, and non-zero values are true.
Last edited on
closed account (Dy7SLyTq)
actually no im correct. my compiler accepts <= 0 as false
actually no im correct. my compiler accepts <= 0 as false

Then it must not be a C or C++ compiler.
@DTSCode

actually no im correct. my compiler accepts <= 0 as false


I am sure you are wrong.
closed account (Dy7SLyTq)
im sure im right
Certainty notwithstanding, you are wrong.
@DTSCode


Boy read books on C/C++ for beginners. It will be useful for you.
Last edited on
closed account (Dy7SLyTq)
i have. my compiler lets me use negative ints as false. but vlad, you just like to say im wrong so im going to stop talking to you now
Then, as has been said, your compiler does not conform to the C or C++ standards and I would recommend getting one that does.
@DTSCode

i have. my compiler lets me use negative ints as false. but vlad, you just like to say im wrong so im going to stop talking to you now


No problem.:) I only do not know what you are doing here with your personal compiler and giving others wrong advices because others have no and never will have your compiler.:)
DTSCode wrote:
actually no im correct. my compiler accepts <= 0 as false
Now there's a lesson to never trust your compiler. Compilers are not always correct or compliant. What compiler is it?

edit: the OPs code is also non-standard.
Last edited on
@DTSCode
See http://en.cppreference.com/w/cpp/language/implicit_cast scroll down to boolean conversions.
le standard wrote:
4.12 Boolean conversions [conv.bool]

A prvalue of arithmetic, unscoped enumeration, pointer, or pointer to member type can be converted to a prvalue of type bool. A zero value, null pointer value, or null member pointer value is converted to false; any other value is converted to true. A prvalue of type std::nullptr_t can be converted to a prvalue of type bool; the resulting value is false.
Topic archived. No new replies allowed.