Question:
int, float or char?
faith l
2007-12-27 12:08:43 UTC
Can someone please tell me what type of expression this is? int, float or char,,,,,beginner here.....

C+N*X?
Thanks for any help.
Five answers:
lucis
2007-12-27 12:44:54 UTC
The operation will fail. C does not "auto-convert" data types according to which is the most apparent one.
Pfo
2007-12-27 13:14:26 UTC
It's going to vary between compilers. All of them will perform N * X first, most likely promoting the int to a float, or throwing an error saying you have to specifically cast one or the other. The remaining operation would get promoted to int or float (depending which one was selected or explicitly cast), since char is the lower type (or again throw an error telling you to explicitly cast one of the variables).
2007-12-27 12:12:36 UTC
Well, if I am not mistaken, this operation will fail, because a 'char' value cannot be used in calculations. Now, if not for that, I would say the result would be a float, as when doing calculations, the results are typically cast to the most flexible type. In other words, if the calc could result in a decimal, the result woud have to be a float.
ctbuckweed
2007-12-27 12:49:17 UTC
for arithmetic, they all get promoted to the most complex type



int N;

char C;

float X;



C+N*X; the compiler does the arithmetic using floats. most compilers also take the 'char' as a signed char (-128 thru 127)
msaeed33
2007-12-27 12:20:50 UTC
It' would a float.



N * X ==> int * float = float

C + (N * X) ==> char + float = float


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...