79125787

Date: 2024-10-25 13:01:18
Score: 1.5
Natty:
Report link

How and by what rule is my array masquerading as an array of arrays?

The code your provided declare buf as a pointer to a dynamically allocated array of ints with a size of max_size. So, buf pointers to the first element of a one-dimensional array of integers.

int* buf = new int[max_size];

In addition, the process function expects a pointer to a pointer to a constant int and the argument being passed to this function is &buf, which has the type int**. Here, buf is of type const int* const*, so buf[c] is dereferencing the first pointer in the array.

void process(const int* const* buf)
{
  int a = 0;
  int ch = 1;
  for(int c = 0; c < ch; ++c)
    for (int i = 0; i < max_size; ++i)
      a += buf[c][i]; // ???
}
Reasons:
  • Blacklisted phrase (1): ???
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Starts with a question (0.5): How
  • Low reputation (0.5):
Posted by: Shelton Liu