C Programming Language Variables

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?

Answer: y will be converted to int and z will be calculated as int
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.

This question appeared in Past Papers (5 times)
ETEA 25 Years Past Papers Subject Wise (Solved) (2 times)
KPK Teacher Past Papers SST PST CT TT PET (2 times)
This question appeared in Subjects (1 times)

Install this app on your device for quick access right from your home screen.