Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   int times long? (http://www.chiefdelphi.com/forums/showthread.php?t=62634)

baop858 27-01-2008 19:46

int times long?
 
What happens when I multiple an int by a long, is the result an long or an int?

Kyle Fenton 27-01-2008 20:00

Re: int times long?
 
Depends, what did you declare your answer variable to be?

int answer

a * b = answer
would result in an integer answer

Roger 27-01-2008 20:08

Re: int times long?
 
I can never remember this, and my K&R is back at school.

int A;
long B;

int answerint;
long answerlong;

I think having a long in the expression casts it to long:

A * B produces a long. But to be sure you can cast it:

answerlong= (long) (A * B);

Alan Anderson 27-01-2008 20:14

Re: int times long?
 
With a long as one of the operands, the Microchip C compiler will do a 32-bit multiplication. The result will be a long.


All times are GMT -5. The time now is 23:44.

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