Passing an array as an argument to a function in C

后端 未结 10 1230
太阳男子
太阳男子 2020-11-22 06:03

I wrote a function containing array as argument, and call it by passing value of array as follows.

void arraytest(int a[])
{
    // changed the array a
    a         


        
10条回答
  •  北恋
    北恋 (楼主)
    2020-11-22 06:37

    When passing an array as a parameter, this

    void arraytest(int a[])
    

    means exactly the same as

    void arraytest(int *a)
    

    so you are modifying the values in main.

    For historical reasons, arrays are not first class citizens and cannot be passed by value.

提交回复
热议问题