-
its a simple question
Hi
in the following condition:
if (x>0) { ... }
the curly brackets are executed if the value of x is above 0.
What is the situation if you have just:
if(x){ ... } ?
Does it mean, 'if the value of x IS 0 then execute the code in the brackets' or does it mean the oposite?
Stupid question I know but ....
Thanks
Buck
-
Hi
if(x > 0) {....} /* this will perform process if x is greater than zero*/
if(x) {....} /*this will perform process if x is not equal to zero...but will perorm when x is less than zero i.e. ( - 1 )*/
when there is only one operand in the comparison...in C true equates to a non zero value and zero is false....therefore in second if statement if(x) means if x is not equal zero (true) process will perform....also curlies are optional when there is only one operation is required after comparison statement...
Code:
if(x)
printf("%d", x);
/*when 2 or more*/
if(x)
{
printf("%d", x);
do something else;
}
-
Thanks bigtamscot
Wood for the trees.....
Buck71