Suppose z is an integer while z and y are long variables. If you write z = z + y; in your C program, which of the following will happen?

  • ACompiler will generate error
  • BZ will be converted to long and z will be calculated as long
  • CY will be converted to int and z will be calculated as int
  • DZ will be converted to long and z will be calculated as int
Show answerHide answer

Correct answer C

In z = z + y;, since z is an int and y is long, y is converted to int (if possible) to match the type of z due to usual type conversion rules. The result is calculated as an int, and this may cause data loss if y exceeds int range.