ICSE Class 10 Computer Applications
Question 5 of 30
Solved Sample Paper 1 — Question 5
Back to all questions 5
Question Question 1(v)
Consider the following code snippet:
float x = 8.25F;
int y;
y = (int)x;What are the values of x and y?
- x = 8.25, y = 8
- x = 8.0, y = 8.0
- x = 8, y = 8.25
- x = 8, y = 8
x = 8.25, y = 8
Reason — float data type can store numbers with decimal and int data type stores signed/unsigned integer values. So, x = 8.25. Then, the user is declaring an int variable y and type casting the float value x to an int and assigning it to y.
When we cast x to an int, the fractional part is truncated and the int value (8) is stored in y. Thus, y = 8.