Need an opinion about this part of code

About the following part of code showing below, I would like a help about
the function of this code.
As I am a begginer in C programming I think that variable y will take price of variable x
Can you give me an example by explaining me in details?

int y;
double x;
x=5789e25;
y=(int)x;
Last edited on
Well the line y=(int)x; is assigning to 'y' the value of 'x' but is casting x which is of type double to type int.

I think in this case x will be a garbage value as any number with an 'e' in it is too large to be printed (i think) and integers only take whole numbers.

A better example would be:

1
2
double y, x = 5.789;
y = (int) x;


Here y will only be given the value of 5 as it is the only whole number(in front of the decimal point).
Topic archived. No new replies allowed.