Added: 3 years ago
From: hhemanth
Views: 3,284
Sort by time | Sort by thread (beta)

Link to this comment:

Share to:

All Comments (7)

Sign In or Sign Up now to post a comment!
  • could you explain what ++ does and why you used == instead of =?

  • ++ is an addition operator. For example, if you had an integer i, the following commands are equivalent.

    c++

    c = c + 1;

    c += 1;

    There is also the operator ++c. The difference between the two ++ operators is when the computation is done. If you do ++c, it will be done before a comparison, and c++ will be done after.

  • == is a comparison operator. It is used in a conditional test. = is an assignment operator, it sets the value of a variable.

    assignment operations do return values (the value being assigned), and, conditional tests simply test for a non-zero state, so, it is possible to write 'valid' code such as if (x = y) which will set x to y and return true if y is nonzero, as opposed to if (x == y), which will not set any values, but will return true if x and y are equal.

  • to clarify, c++ returns the value of c before being incremented. ++c returns the value of c after being incremented.

    c = 3; d = c++; // now c is 4 and d is 3.

    c = 3; d = ++c; // now c is 4 and d is also 4.

Loading...
Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more