Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: value of TRUE??? Message-ID: <9812@smoke.BRL.MIL> Date: 8 Mar 89 02:20:36 GMT References: <987@infmx.UUCP> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 36 In article <987@infmx.UUCP> kevinf@infmx.UUCP (Kevin Franden) writes: >given: :The if() statement will evaluate to true provided that > the argument does not evaluate to 0. (ie a=3; if (a)...) >Is then the value of true any nonzero integer? >If it's not, is it equivelent to a nonzero integer? >What does if (a=3) evaluate to? You're adding to your own confusion by trying to bundle too much together. The C language itself has no official "true" value, so trying to decide what that value "is" is inherently misleading. First of all, the "if" STATEMENT does not have a value. You cannot say a = if(x)y;else z; (Some Algol-like languages would support this, but C doesn't; it has a ?: operator instead.) Next, the value of what would appear to be a Boolean or relational expression is either 0 or 1, and it's an arithmetic expression in C. Third, the condition used for if(), while(), etc. is any arithmetic expression, not just those that appear to be Boolean. The condition is taken to be "true" if it has any nonzero value. Thus, if(a=3) assigns the value 3 to the variable a, and then, since the assignment expression has the value 3 which is nonzero, the "true" branch of the "if" statement is taken. The assignment statement i = j > 2; will give the variable i the value 0 unless the value of j exceeds 2, in which case i will be assigned the value 1. I don't recommend mixing conceptually arithmetic and Boolean operations even though the C language is designed to allow it.