int N;
char C
float X
what is the type of the expression C+N*X?
a. char
b. int
c. float
d. The expression contains a syntax error
Given the following declarations:?
d if you intentioally left the semi colons off the ends of the lines.
Otherwise, I'd guess B.
Reply:The expression does not contain any syntax error.The answer of this expression can be of int,float or char type whatever the user wants.
why int :when an integer value is multiplied to a float value the answer will be in float and all the characters have their values in ASCII code ,this ASCII code value will be added to N*X and the answer is in float and if we are displaying our answer in int type the decimal part will be discarded.
Similarly one can easily understand how the answer will come in float or char.
Note that when we display our answer in char type then integer value calculated after evaluating the expression will be converted into ASCII value character.
Reply:the answer will be a float!!
C+N will be an int and ANY int times a float will and must be a float unless it is cast back to an int (or char as char is just a one byte int)
this is the type of problem that you can easily code and rrun to verify. You should try to do your own homework it is only going to make you a better coder
Reply:what language is this? Its mostly going to be a syntax error.. you are trying the add a char to a int. But it might also take the ascii value of C and add.. in which case your result will depend whether N id dvisible by X.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment