C Programming - Arrays - Discussion

Discussion Forum : Arrays - General Questions (Q.No. 3)
3.
In C, if you pass an array as an argument to a function, what actually gets passed?
Value of elements in array
First element of the array
Base address of the array
Address of the last element of array
Answer: Option
Explanation:

The statement 'C' is correct. When we pass an array as a funtion argument, the base address of the array will be passed.

Discussion:
31 comments Page 1 of 4.

Ganesh said:   1 decade ago
Since arrays name represent its base adress.

Shakil said:   1 decade ago
Can anyone exaplin this in detail please.

Sameera said:   1 decade ago
Take a[5], it will store address of a[0] in a. when it will access the array only by a it will increment a or it will take a+1,a+2,a+3 and so on.

When array is passed to any function we will pass as

add(a);

In definition it will take it in pointer and access whole array

Hence at the time of passing array it will pass only base address i.e. address of first element of array.

Poonam said:   1 decade ago
What is base address ?

Srilakshmi said:   1 decade ago
When an array is declared along with required no. Of memory locations then compiler allocates extra memory location under the array name and stores address of first element ie. , base address of array.

Mayank said:   1 decade ago
What is difference in base address and first element address?

Suraj said:   1 decade ago
@Mayank....
Both r same dude.

Sailusha said:   1 decade ago
Thanks Sameera.

Sri ram said:   1 decade ago
If we print the array without using loops for example

printf ("%d\n", a) the output will be the address of the first element nothing but the base address.

So if we pass this array to a function as an argument it will take the base address of that array and the output will be the base address of that array.

Sri ram said:   1 decade ago
If we print an array without using loop like printf ("%d", array) then the first element address will be printed that is base address.

So if we pass array in a function as an argument, base address of array will be taken.


Post your comments here:

Your comments will be displayed after verification.