Predict values after return-type conversion

The functions below are compiled as C17 on a system where unsigned char holds 8 bits (values 0 to 255).


C
int halfInt(double x) { return x / 2; }
double meanInt(int a, int b) { return (a + b) / 2; }
double meanReal(int a, int b) { return (a + b) / 2.0; }
unsigned char wrapByte(int n) { return n; }


Each call in the table is printed with printf("%d\n", ...) when the function returns an integer type, and with printf("%.1f\n", ...) when it returns double. Enter exactly what each call prints, as a whole number or a number with one decimal place.

CallPrinted output
halfInt(7.0)
halfInt(-7.0)
meanInt(7, 4)
meanReal(7, 4)
wrapByte(300)

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Functions and Void Return Types Questions: