Simvik

Does it fit in a byte?

Combine two comparisons with a logical operator. An easy embedded C problem (Variables and operators), run and graded in the browser.

easy · Variables and operators · logical-operators · ranges

A byte holds a whole number from 0 to 255. Before storing a value in one, it is worth checking that it fits.

Return 1 if v is between 0 and 255 inclusive, and 0 otherwise. && means "and", so a && b is 1 only when both sides are true.

Starter code

int fits_in_byte(int v) {
  return 0;
}

Example tests

A value that fits

printf("%d\n", fits_in_byte(100));

Expected output:

1

A value that is too large

printf("%d\n", fits_in_byte(300));

Expected output:

0

Learn it first

More Variables and operators problems