77. Byte Buffer Indexing

Create a class ByteBuffer that stores an array of exactly 8 bytes using uint8_t and allows indexed access using an overloaded operator[].

The class must support:

  • Writing to a specific byte

    buffer[i] = value;
    
  • Reading a specific byte

    x = buffer[i];
    

The overloaded operator must return a reference so that assignments work correctly.

Program Behavior:

  1. Read 8 integer values to initialize the buffer
  2. Read an index idx and a value v
  3. Assign the new value using the overloaded operator
  4. Print all 8 bytes separated by spaces

Numeric Rules (Explicit):

  • All stored values are uint8_t
  • Input values will be in the range 0 to 255 inclusive
  • No overflow, saturation, or wraparound handling is required
  • Index will always be between 0 and 7

Example Input:

1 2 3 4 5 6 7 8
3 99

Example Output:

1 2 3 99 5 6 7 8

Constraints:

  • Use uint8_t internally to store exactly 8 bytes
  • operator[] must return a reference
  • Index range is guaranteed valid (0–7)
  • Value range is guaranteed valid (0–255)

 

 

 

Loading...

Input

1 2 3 4 5 6 7 8 3 99

Expected Output

1 2 3 99 5 6 7 8