Thread: C Modulus Compound Operator

  1. #1
    Registered User LowWaterMark's Avatar
    Join Date
    Aug 2008
    Posts
    12

    C Modulus Compound Operator

    I'm in the embryonic stages of teaching myself C and am confused about using the modulus operator in a compound operation. Given:

    Code:
    int i = 17;
    
    int j = 5;
    
    int answi;
    
    answi = i / j;  /* 3 is stored in answi */
    
    answi %= 2;  /* 1, the remainder of 3/2, is now stored in answi */

    Am I close?

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Right. (All the compound operators a ?= b turn into a = a ? b, where ? is plus or times or modulus (in this case) or whatever.)

  3. #3
    Registered User LowWaterMark's Avatar
    Join Date
    Aug 2008
    Posts
    12
    and gratis! Thanks much!
    Last edited by LowWaterMark; 08-10-2008 at 12:16 PM. Reason: typo

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. modulus operator with double operands?
    By chickenandfries in forum C Programming
    Replies: 7
    Last Post: 03-28-2008, 07:21 AM
  2. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 07:05 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. operator overloading and dynamic memory program
    By jlmac2001 in forum C++ Programming
    Replies: 3
    Last Post: 04-06-2003, 11:51 PM