Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   syntax in c??? (http://www.chiefdelphi.com/forums/showthread.php?t=27343)

Pattyta 30-03-2004 09:21

syntax in c???
 
does the symbol % represent remainder as in java ???? :confused:

thnx
rockie team

Chris Hibner 30-03-2004 09:23

Re: syntax in c???
 
yes.

gnormhurst 30-03-2004 10:48

Re: syntax in c???
 
% is usually called the "mod" or "modulus" operator, but that means the same thing as remainder.

A couple of things to be careful of. The behavior of % with negative operands is not standardized. In
Code:

( a % b )
if a or b is negative, C only guarantees that the absolute value of the result will be less than b. Better make sure the numbers are positive. One way to do this is to add a multiple of the second operand to the first operand. But be careful of precedence.

The order of precedence of '%' is the same as for '*' and '/', which is higher than for '+' and '-'. So
Code:

( ii + 16 % 8 )
evaluates the same as
Code:

(ii + 0)
which is just
Code:

(ii)
Use parens to get what you want:
Code:

( (ii+16) % 8 )
It also makes for more readable code.

-norm


All times are GMT -5. The time now is 02:50.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi