0

I'm trying to create a function that displays an array's contents.

void show(string arr[]){
    for(int i = 0; i < sizeof(arr)/sizeof(arr[0]); i++){
        cout << arr[i] << endl;
    }
}

If I replace sizeof(arr)/sizeof(arr[0]) with the length of the array I'm inputting into the function it works. Which confuses me since sizeof(arr)/sizeof(arr[0]) evaluates to the length of the array.

Why is this happening?

Here's the calling code if it's relevant.

int main()
{
    string arr[] = {"word", "word", "word", "word", "word"};
    show(arr);
    return 0;
}
sabertenn
  • 31
  • 4

0 Answers0