Computer Science, asked by adityaraj1447, 8 months ago

When you pass an array as an argument to a function, what actually gets passed

a)    address of the array


b)    value of the elements of the array


c)    address of the first element of the array


d)    number of elements of the array.

Answers

Answered by dreamrob
0

Answer:

We are passing the base address of the array.

So, option (a) is correct. We pas_s the address of the array which is the address of the first element of the array.

Example:

int addition(int b[] , int len)

{

  int sum = 0;

  for(int i = 0 ; i < len ; i++)

  {

     sum = sum + b[i];

  }

  return sum;

}

int main()

{

  int a[] = {1 , 2 , 3 , 4};

  int len = sizeof(a) / sizeof(a[0]);

  printf("%d" , addition(a , len));

  return 0;

}

We are not passing the whole array. We are just passing the base address of the array.  

An array name is always treated as a pointer that contains the base address of the array.

Similar questions