View Full Version : 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
Depends, what did you declare your answer variable to be?
int answer
a * b = answer
would result in an integer answer
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
With a long as one of the operands, the Microchip C compiler will do a 32-bit multiplication. The result will be a long.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.