数组索引与数组元素

Array Indices vs Array Elements

这是与以下问题相关的一种元问题:

最初提出的问题(强调我的):

I have a std::vector<int> data; and I want to find all the array indexes that are less than 9 and add them to a result vector.

然后我将其编辑为:

I have a std::vector<int> data, and I want to find all elements that are less than 9 and add them to a result vector.

然后另一个用户将其编辑为:

I have a std::vector<int> data and I want to find all array indices at which the elements are less than 9 and add them to a result vector.

我已将其标记为让版主恢复此内容,说明:

I reworded this question (whosebug.com/posts/38798841/revisions) with the main goal of replacing "array indexes" with "elements", since that is what's actually being asked - and referring to "indexes/indices" in this context causes some confusion. However, user Aconcagua has overturned this crucial part of my edit. It's my belief that his latest edit should be rolled back.

它被拒绝了,原因是:

Aconcagua's edit is correct; the user is collecting array indicies, not the array elements themselves

现在,我不太明白版主说的是什么 - "the user is collecting array indicies"。在我看来,索引是数组中元素的位置。比如C语言中:

char array[] = {'t', 'e', 's', 't'};
int index = 1;
char element = array[index];
printf('%c', element);

我根本不明白他会如何或为什么收集 "indices" 而不是 "elements"。谁能澄清一下,这样我才能真正理解?

在链接问题顶部的示例代码中:

for (int i = 0; i < data.size(); ++i)
    if (data[i] < 9)
        r.push_back(i);

注意 i 被添加到向量中,不是 data[i].

i 是感兴趣元素的索引,是正在存储的内容,而不是存储在 data[i] 的值,它是 data 向量中的元素。