What does += mean when setting the y distance?

Discussion in 'iOS Programming' started by StevenHu, Feb 12, 2010.

  1. StevenHu macrumors member

    Joined:
    Sep 3, 2009
    Location:
    Southern CA
    #1
    In Apple's UICatalog, some segmented controls' y distance is set at "yPlacement += 30;"

    If I set it at "yPlacement = 30;" it moves up around 10 pixels from current position (so it's 20 pixels from the top of the window).
    If I set it at "yPlacement + 30;" it moves up around 30 pixels (so it's 30 pixels from the top of the window).

    Can anyone help me understand this?

    Thanks,
    Steve
     
  2. voidptr macrumors regular

    Joined:
    Jan 11, 2007
    #2
    += is the C assignment by addition operator. It takes whatever is in the variable on the left side, adds whatever value is on the right side, and stores the result back into the variable on the left.

    Code:
    int x = 30;
    x += 3;
    
    After the second line, x will contain 33.

    Wikipedia has a reference for all the C operators: http://en.wikipedia.org/wiki/Operators_in_C_and_C++
     
  3. StevenHu thread starter macrumors member

    Joined:
    Sep 3, 2009
    Location:
    Southern CA

Share This Page