Thread: "evaluate to zero"?

  1. #1
    jjj
    Guest

    Smile "evaluate to zero"?

    hey all, I'm glad to be back and get this thing busy!

    here is qoute from my book by schildt, and tell me if this is important to my programming ability and if I need to really know it:

    context: the if statement
    "In C, an expression is true if it evaluates to any nonzero value. If it evaluates to zero it is false."

    that is where my book stops talking about it. I know it is short, but hey somebody has to be free and looking for some fun(just don't lie to me and play, not now, I got a class!).

    jjj

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826

    Re: "evaluate to zero"?

    Originally posted by jjj
    hey all, I'm glad to be back and get this thing busy!

    here is qoute from my book by schildt, and tell me if this is important to my programming ability and if I need to really know it:
    Well that's your frist problem. You're reading a Schildt book.

    Now on to the question:
    Code:
    int x = 1;
    
    if( x == 1 )
    This statement is true. x is equal to one, so the expression "x == 1" is translated to 1, or true.

    Code:
    int x = 1;
    
    if( x != 1 )
    This statement evaluates to zero. It is false. Since x is actually one, the expression "x != 1" evaluates to zero, meaning that when this check happens, the outcome of it is zero, or false.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    jjj
    Guest
    that was a diss, ouch, I happen to think schildt is ok, it works for me and is better than Dietel & Dietel, FOR ME.

    I think I see, if something evaluates to "false" then a zero gets sent back to the compiler and that gets counted as a false.

    THIS IS SEPERATE TOPIC(MAYBE): when the main() function finishes we say "return 0". Is that a sepertate topic and logic than the one just described for "if" statements? It does "return 0"(the main() does), but according to my understanding that is done just to tell the compiler(or system) that the program ran successfully without problems, so they are like seperate stuff.
    ?????(this is where someone jumps in)

  4. #4
    Registered User
    Join Date
    Sep 2002
    Posts
    16
    Obviously, since main is a function just like anything else, it has a return type. Yes, "return 0;" just tells the system that main compiled fine.


    Of course, this only makes a difference if main is written as "int main(){some code here }".
    If your code reads "void main(){some code here }" your return type is void and the whole idea of returning anything is bunk to begin with.
    don't be a two-bit user

  5. #5
    Green Member Cshot's Avatar
    Join Date
    Jun 2002
    Posts
    892
    >>If your code reads "void main(){some code here }" your return type is void and the whole idea of returning anything is bunk to begin with.

    But your code should never have void main() in the first place! Right? Right?
    Try not.
    Do or do not.
    There is no try.

    - Master Yoda

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>Obviously, since main is a function just like anything else, it has a return type. Yes, "return 0;" just tells the system that main compiled fine.
    The return value from main() tells that OS and therefore the caller what main returned with. It doesn't tell you anything about it's compilation. Simply put, if main() doesn't compile, you can't run it, and therefore it can't return anything... but that's obvious


    >>But your code should never have void main() in the first place! Right? Right?
    ...and one more "right" for luck.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed