Why 4.0 can't be declared as int?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why 4.0 can't be declared as int??

My sir told me that if we declare int as a decimal it will take the number before the decimal . But when I entered it .It displayed an error. Plz help.

18th Aug 2017, 4:36 PM
Abhi
Abhi - avatar
1 Answer
+ 1
if your sir has told exactly the same thing as you have written then your sir is wrong. In java it is not possible but it is possible in C. You have to perform type casting in java //java program , output will be 4 class ABC { public static void main(String args[]) { int a=(int)4.1;//typecasting System.out.print(a); } } //c program, output will be 4 #include<studio.h> int main() { int a=4.1; printf("%d",a); return 0; }
18th Aug 2017, 5:01 PM
Rishi Anand
Rishi Anand - avatar