Multiple choice

The library function sqrt operates on a double precision argument. If i is an integer variable, which one of the following calls would correctly compute sqrt(i)?

  1. sqrt((double)i)

  2. (double) sqrt(i)

  3. (double)(sqrt(i))

  4. sqrt(i)

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The sqrt function expects a double argument. Casting the integer i to double ensures the correct function overload or conversion is used.