assigning float into int variable causes no warning

前端 未结 3 812
感情败类
感情败类 2021-01-18 07:27

So, given the following code:

int main(void) {
  int i;
  i = 12.1234;
  i++;
  return 0;
}

I compiled the code and I expected and wanted t

3条回答
  •  遇见更好的自我
    2021-01-18 07:36

    A float value can be assigned to an integer variable but an implicit conversion occurs when compiler forces a float value to be assigned as an integer.

    The digits after the decimal notation in the float value get lost after assigning a float to an integer.

    Edit: casting -> conversion

    Thanks R..

提交回复
热议问题