pointer equation

This is a discussion on pointer equation within the C Programming forums, part of the General Programming Boards category; Hi in the code [code] {while ( (*s++ = *t++) != '

Thread: pointer equation

');} [\code] i was wondering if both *t and ...

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    70

    pointer equation

    Hi
    in the code
    [code]
    {while ( (*s++ = *t++) != '\0');}
    [\code]

    i was wondering if both *t and *s are checked for the null. or is it just *t?

  2. #2
    Registered User
    Join Date
    May 2004
    Posts
    127
    Quote Originally Posted by studentc
    Hi
    in the code
    [code]
    {while ( (*s++ = *t++) != '\0');}
    [\code]

    i was wondering if both *t and *s are checked for the null. or is it just *t?
    Only the result of the expression is checked for the null character. The result of the expression is the value of *s. However, because the expression was assignment, it's a safe bet that *t and *s have the same value.
    When writing a specialization, be careful about its location; or to make it compile will be such a trial as to kindle its self-immolation.

  3. #3
    Registered User
    Join Date
    May 2004
    Posts
    70
    so
    you mean to say
    if there is an expression

    a=b=c;

    does that mean the result of the expression is a

  4. #4
    Registered User
    Join Date
    May 2004
    Posts
    127
    Quote Originally Posted by studentc
    so
    you mean to say
    if there is an expression

    a=b=c;

    does that mean the result of the expression is a
    Yes.
    When writing a specialization, be careful about its location; or to make it compile will be such a trial as to kindle its self-immolation.

  5. #5
    Registered User
    Join Date
    Apr 2004
    Posts
    2
    Quote Originally Posted by studentc
    so
    you mean to say
    if there is an expression

    a=b=c;

    does that mean the result of the expression is a
    Yes, but after a has been assigned the value of b, which in turn has been assigned the value of c.

  6. #6
    Registered User
    Join Date
    May 2004
    Posts
    70
    so is
    a first assigned the value of b,
    or b first assigned the value of c

  7. #7
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,646
    Operator Precedence and Associativity

    Assignment has right-to-left associativity.

    gg

    [EDIT]
    Ignore the C++ operators in that table

  8. #8
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    b is assigned the value of c, then a is assigned the value of b. Assignment is performed right to left, so it would look like this if fully parenthesized:
    Code:
    (a = (b = c));
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-24-2008, 10:16 AM
  2. Parameter passing with pointer to pointer
    By notsure in forum C++ Programming
    Replies: 15
    Last Post: 08-12-2006, 07:12 AM
  3. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  4. How did you master pointers?
    By Afrinux in forum C Programming
    Replies: 15
    Last Post: 01-17-2006, 07:23 PM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21