156k views
5 votes
Given the code segment below, list the complete range of possible integer values that field il can hold. struct ex int i1:2; int i2: 3 ; ;

User Mark Rowe
by
7.9k points

1 Answer

6 votes

The code segment `struct ex { int i1:2; int i2:3; };` declares a structure named `ex` with two integer fields `i1` and `i2` with specified bit sizes of 2 and 3 respectively. The bit size determines the range of possible integer values that the field can hold.

For `i1` with a bit size of 2, it can hold the following integer values:

- -2: Binary representation: `10`

- -1: Binary representation: `11`

- 0: Binary representation: `00`

- 1: Binary representation: `01`

So, the range of possible integer values for `i1` is -2 to 1.

For `i2` with a bit size of 3, it can hold the following integer values:

- -4: Binary representation: `100`

- -3: Binary representation: `101`

- -2: Binary representation: `110`

- -1: Binary representation: `111`

- 0: Binary representation: `000`

- 1: Binary representation: `001`

- 2: Binary representation: `010`

- 3: Binary representation: `011`

So, the range of possible integer values for `i2` is -4 to 3.

User SaplingPro
by
8.2k points