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

后端 未结 13 2116
[愿得一人]
[愿得一人] 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条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-21 05:16

    In c++ you can pass an array by reference for this very purpose :

    void foo(int (&array)[10])
    {
        std::cout << sizeof(array) << "\n";
    }
    

提交回复
热议问题