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

后端 未结 13 2127
[愿得一人]
[愿得一人] 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 04:54

    In C language when you pass the array as an argument to the function , it is automatically converted into pointer ,array passing from one function other function is know as call by reference . That is the reason the called function only receives the pointer which point to the first element of function This is the reason

    fun(int a[]) is similar to fun(int *a) ;

    so when you print the size of array it will print the size of first element.

提交回复
热议问题