Why isn't the size of an array parameter the same as within main?

后端 未结 13 2188
[愿得一人]
[愿得一人] 2020-11-21 04:13

Why isn\'t the size of an array sent as a parameter the same as within main?

#include 

void PrintSize(int p_someArray[10]);

int main () {
           


        
13条回答
  •  旧时难觅i
    2020-11-21 05:12

    Because arrays decay into pointers when they are passed as parameters. This is how C works, although you can pass "arrays" in C++ by reference and overcome this issue. Note that you can pass arrays of different sizes to this function:

     // 10 is superfluous here! You can pass an array of different size!
    void PrintSize(int p_someArray[10]);
    

提交回复
热议问题