write a program to convert floating point values into its integral equivalent using pointer
Answers
Answered by
3
You can do it by using type casting. The syntax is-
Example:
float x;
x=3.14;
int y;
y= (int)x;
printf(“%d”, y);
Output:
3
What really happened? I’ll explain it by taking a famous analogy.
Think of a bucket completely filled with water. Now suppose you have a mug. What is the maximum water you can take out of the bucket? Answer- A mug.
Here the bucket is float (4 bytes), and the mug is int (2 bytes). Type casting is the process of filling, and water (data) is lost while doing so.
Hope this helps;)
Example:
float x;
x=3.14;
int y;
y= (int)x;
printf(“%d”, y);
Output:
3
What really happened? I’ll explain it by taking a famous analogy.
Think of a bucket completely filled with water. Now suppose you have a mug. What is the maximum water you can take out of the bucket? Answer- A mug.
Here the bucket is float (4 bytes), and the mug is int (2 bytes). Type casting is the process of filling, and water (data) is lost while doing so.
Hope this helps;)
Similar questions
Math,
8 months ago
Social Sciences,
8 months ago
Accountancy,
8 months ago
Physics,
1 year ago
Physics,
1 year ago
Math,
1 year ago