What is this operator?

This is a discussion on What is this operator? within the C Programming forums, part of the General Programming Boards category; Could someone please confirm what the following line does... n %= 5; (where n is an integer). Thanks....

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    98

    What is this operator?

    Could someone please confirm what the following line does...

    n %= 5;

    (where n is an integer).

    Thanks.

  2. #2
    Registered User penney's Avatar
    Join Date
    Jan 2003
    Posts
    47

    Modulus Operator

    In your case n%=5 can be translated into

    n = n % 5 which in turn means: Return the remainder from dividing n by 5 and store the result to n. This has the same effect as keeping n in the range of 0 to 4.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 07:05 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. Operator Overloading (Bug, or error in code?)
    By QuietWhistler in forum C++ Programming
    Replies: 2
    Last Post: 01-25-2006, 07:38 AM
  4. Destructor - Execution problem
    By triste in forum C++ Programming
    Replies: 16
    Last Post: 09-26-2004, 01:57 PM
  5. operator overloading and dynamic memory program
    By jlmac2001 in forum C++ Programming
    Replies: 3
    Last Post: 04-06-2003, 11:51 PM

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