
Hi Harkirat,
Great question — it’s something many learners wonder about.
When you write:
int intValue = (int) doubleValue;
the part (int) is called explicit type casting. You're telling the compiler clearly: "Yes, I know doubleValue is a double, and I want to convert it to an integer."
Even though you're storing the result in an int, if you skip the cast:
int intValue = doubleValue;
C will do an implicit conversion — it still works, but the compiler may give you a warning, especially if there’s a chance of losing data (like dropping decimal points).
Using (int) makes your intention clear and avoids confusion. It’s also a good habit when converting between types, especially when precision matters.
If you have more questions, I am here to help.
Our Experts
Sudip BhandariHead of Growth/Marketing
Apekchhya ShresthaSenior Product Manager
Kelish RaiTechnical Content Writer
Abhilekh GautamSystem Engineer
Palistha SinghTechnical Content Writer
Sarthak BaralSenior Content Editor
Saujanya Poudel
Abhay Jajodia
Nisha SharmaTechnical Content Writer
Udayan ShakyaTechnical Content Writer
