Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Who can teach me?

kinkileekinkilee Posts: 4Member
Explain the steps of determining the value of

Comments

  • AsmGuru62AsmGuru62 Posts: 6,519Member
    [code]
    : int x = 6, *p;

    [color=Green]/**
    Address p is pointed to x
    **/[/color]
    : p = &x;

    [color=Green]/**
    First, find out what value is on the right side of
    the expression:

    ++x - first, increment x and THEN USE it in expression
    x++ - first, USE x in expression and THEN increment it

    1. Incremented x will mean 7
    2. 7 must be added to a location pointed by p
    3. But, location p points to x, which is now 7
    4. 7+7 = 14 (x will be now 14)
    **/[/color]
    : *p += ++x;
    [/code]
  • kinkileekinkilee Posts: 4Member
    so, the answer is 14?

    what is the meaning of *p?
    (int *p) = p is a pointer to an integer. Rite?

    Then, now the answer is 7, your explained is well, i can understand.

    But, how become 7+7=14?

    : *p += ++x; means what?

    Sorry! I'm a stupid...
  • keysrecoverkeysrecover Posts: 8Member
    this is simple:
    *p is the value of pointer p
    ++x means x=x+1
    *p+=++x equivalent to *p=*p+++x or *p=*p+x+1





    _______________________________
    ???????? ?????? ??????| employment / freelance jobs
  • HK_MP5KPDWHK_MP5KPDW Posts: 767Member ✭✭✭
    Undefined behavior.
Sign In or Register to comment.