What does % really mean?

This is a discussion on What does % really mean? within the C++ Programming forums, part of the General Programming Boards category; What does this mean? Code: res=provnum%2; Does that mean that when the value provnum is inputted it has two decisions ...

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    19

    What does % really mean?

    What does this mean?

    Code:
    res=provnum%2;
    Does that mean that when the value provnum is inputted it has two decisions to make and those two decisions are assigned to res?

    Thanks.

  2. #2
    Registered User
    Join Date
    Aug 2004
    Location
    San Diego, CA
    Posts
    313
    % = Modulus (spelling might be off.)

    10 % 2 = 0. Ten, devided by 2, has a remander of zero.

    10 % 3 = 1. Ten, devided by 3, has a remander of one.

    All modulus is giving you is the remainder of a devision between lvalue and rvalue.

  3. #3
    Registered User
    Join Date
    Feb 2005
    Posts
    19
    Yeah that I understand but, in the code itself... (the example code I gave) what is it telling me about the code?

  4. #4
    Registered User
    Join Date
    Aug 2004
    Location
    San Diego, CA
    Posts
    313
    Quote Originally Posted by MyDestiny
    Yeah that I understand but, in the code itself... (the example code I gave) what is it telling me about the code?
    res stores the remainder of the division of provnum and 2.

    res = (remainder of) provnum / 2.

  5. #5
    Mad OnionKnight's Avatar
    Join Date
    Jan 2005
    Location
    UmeŚ, Sweden
    Posts
    555
    Quote Originally Posted by MyDestiny
    Yeah that I understand but, in the code itself... (the example code I gave) what is it telling me about the code?
    res will contain information about if provnum is either an odd or an even number. If it's even res is 0 and if it's odd then res is 1.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Sorting whit MPI
    By isato in forum C Programming
    Replies: 0
    Last Post: 03-03-2009, 09:38 AM
  2. wats the fault...
    By ElemenT.usha in forum C Programming
    Replies: 17
    Last Post: 01-04-2008, 12:52 PM
  3. Reading Characters from file into multi-dimensional array
    By damonbrinkley in forum C Programming
    Replies: 9
    Last Post: 02-24-2005, 12:31 PM
  4. Mazes(urgent!!);
    By Oid21 in forum Game Programming
    Replies: 11
    Last Post: 03-18-2003, 02:29 AM
  5. The A-Bomb of Board Discussion: -∆-
    By Aran in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 10-21-2001, 10:39 AM

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