Thread: fault in eBook Alex?

  1. #1
    Registered User
    Join Date
    May 2012
    Posts
    15

    Lightbulb fault in eBook Alex?

    Hello everyone,
    I just bought Alex' eBook, and i noticed somethign that i thought was wrong.
    In the book, there is this if statement:

    Code:
    if ( x != 0 && 10 / x < 2 ){
    cout << "10 / x is less than 2";
    }
    Alex said that this will first check if x != 0, and then if 10 / x smaller is than 2. But i've read somewhere that c++ code is read from right to left. so then the first statement to be checked would be if 10 / x < 2.

    So now i'm curious what is the truth XD

    Thanks for any replies!

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Logical AND Operator: && (C++)

    The first operand is completely evaluated and all side effects are completed before continuing evaluation of the logical AND expression.

  3. #3
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    But i've read somewhere that c++ code is read from right to left.
    You misunderstood.

    Operator precedence and associativity are things, but only a few, the assignment related operators, are evaluated "right-to-left".

    Soma

  4. #4
    Registered User
    Join Date
    May 2012
    Posts
    15
    Thanks for the replies, now i understand
    Now, let's get on with the tutorial!

  5. #5
    Registered User
    Join Date
    May 2012
    Posts
    15

    Question

    Code:
    int main (){
    for ( int i = 0; i < 10; i++ )
    {
    cout << '\t' << i; // \t represents a tab character, which will
    format our output nicely
    }
    cout << '\n';
    for ( int i = 0; i < 10; ++i )
    {
    cout << i;
    for ( int j = 0; j < 10; ++j )
    {
    cout << '\t' << i * j;
    }
    cout << '\n';
    }
    }
    This is another code i see in this book.
    Now another question is, will from line 6 that "format our output nicely" considered comment?
    shouldnt it because it's 2 lines be within /* x */ ?

  6. #6
    [](){}(); manasij7479's Avatar
    Join Date
    Feb 2011
    Location
    *nullptr
    Posts
    2,657
    Quote Originally Posted by Reinmaster7 View Post
    This is another code i see in this book.
    Now another question is, will from line 6 that "format our output nicely" considered comment?
    shouldnt it because it's 2 lines be within /* x */ ?
    That is probably a page formatting issue.
    Just assume that it is on the same line in the code.

  7. #7
    Registered User
    Join Date
    May 2012
    Posts
    15
    I thought so

  8. #8
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    You should have gotten a file (sample_code.zip) that includes the source code as source code.

    The relevant file is properly formatted as code. In the future, follow allowing with the real source samples while reading the book. I'm told that they were all tested with a compiler so they should all be largely correct.

    This should be reported as errata. (I'll try and send a private message to the author on your behalf later. I don't believe you can send them until you have enough posts.)

    Soma

  9. #9
    Administrator webmaster's Avatar
    Join Date
    Aug 2001
    Posts
    1,012
    @Reinmaster7 Thanks for pointing that out. It looks like what happened is that this was a single line in the source document for the book, but it line wrapped, so it looks like it's on a second line when displayed. I'll get this fixed!

    @phantomotap Thanks for alerting me to this thread!

  10. #10
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    O_o

    Wow. I forgot about this.

    I was supposed to come back and make another note.

    For Reinmaster7: no one likes getting bug reports that aren't bugs. I'm not talking about this instance. This was a bug. I'm talking about for the future. If you find another something that you think might be a bug ask at the forum for confirmation before you fire off a report. (Said just in case you wouldn't have done.)

    Soma

  11. #11
    Registered User
    Join Date
    May 2012
    Posts
    15
    Quote Originally Posted by phantomotap View Post
    O_o

    Wow. I forgot about this.

    I was supposed to come back and make another note.

    For Reinmaster7: no one likes getting bug reports that aren't bugs. I'm not talking about this instance. This was a bug. I'm talking about for the future. If you find another something that you think might be a bug ask at the forum for confirmation before you fire off a report. (Said just in case you wouldn't have done.)

    Soma
    did i post a report? no, i asked if this was a fault xD
    It was just a question!
    and further in the book i found 2 typos xD, not in sample codes but in normal text. somewhere there is "appy" instead of "apply".
    I don't mind it being there, but i think the author of this book, Alex, wants his book best possible right? :P

  12. #12
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    no, i asked if this was a fault
    I know. That was my point.

    What you've done here is exactly what I was asking you to do in the future.

    Soma

  13. #13
    Administrator webmaster's Avatar
    Join Date
    Aug 2001
    Posts
    1,012
    Quote Originally Posted by Reinmaster7 View Post
    and further in the book i found 2 typos xD, not in sample codes but in normal text. somewhere there is "appy" instead of "apply".
    I don't mind it being there, but i think the author of this book, Alex, wants his book best possible right? :P
    Thanks! I believe I've already fixed the appy/apply issue, but if you find any more typos you can just send me an email at [email protected] and I'll get them corrected.

  14. #14
    Administrator webmaster's Avatar
    Join Date
    Aug 2001
    Posts
    1,012
    Quote Originally Posted by Reinmaster7 View Post
    and further in the book i found 2 typos xD, not in sample codes but in normal text. somewhere there is "appy" instead of "apply".
    I don't mind it being there, but i think the author of this book, Alex, wants his book best possible right? :P
    Thanks! I believe I've already fixed the appy/apply issue, but if you find any more typos you can just send me an email at [email protected] and I'll get them corrected.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ebook on graphics in c/c++
    By babai123 in forum Game Programming
    Replies: 2
    Last Post: 07-13-2008, 10:24 PM
  2. ebook readers
    By confuted in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 07-03-2003, 11:49 AM
  3. ebook
    By Shakespeare in forum Windows Programming
    Replies: 0
    Last Post: 07-31-2002, 06:14 AM