What will be the value of i?
float x = 3.3;
int i;

i = (int) x;

Options
- 3
- 3.3
- 3.0
- 3.00


CORRECT ANSWER : 3

Discussion Board
output- Error

-In this program, syntax error because syntax for printing a value of 'i' should be printf(ā€œ%dā€,i);
-Data type of 'i' int hence, we use '%d'. If we use this syntax in program, then Answer = 3.
-i= (int) x; It is an explicit type conversion and (int) is the type casting keyword.
Here, data loss while converting float value of x to int. i.e .3 is lost during conversion.

Sapna 02-14-2017 11:33 PM

It is explicit

it is explicit bcs, it convert to double to int//
right ans.

Akram khan 04-10-2014 01:56 AM

syntax error

should be printf("%d",i);

anonymouse 04-2-2014 11:44 PM

Write your comments


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)


Advertisement