Skip to content
Sign in
Computer

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?

Tap an option to check the answer. You can also press A–D.

Show answer

Correct answer: C) y will be converted to int and z will be calculated as int

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.
Explanation
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.