Passing an array as an argument to a function in C

后端 未结 10 1233
太阳男子
太阳男子 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:15

    You are passing the value of the memory location of the first member of the array.

    Therefore when you start modifying the array inside the function, you are modifying the original array.

    Remember that a[1] is *(a+1).

提交回复
热议问题