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 2 of 4.

Sricharan said:   1 decade ago
Suppose int arr[]={10,20,30};
calculate base address:
treat base address as 500
arr[1]=*(arr[0]+1);
i.e,*(500+1)=*(502)
so 502 pointing to element 20.so arr[1]=20

like wise......
arr[0]=10;
arr[2]=30;

@poonam

Praveena said:   1 decade ago
What is first element address?

Ravneet said:   1 decade ago
@Poonam.

Base address is the address of list element of the array.

If we pass only name of the Array to a function, it basically means that The base address is passed.

Promila said:   1 decade ago
Base address of the array and array passing by reference are same or different.

Vini said:   1 decade ago
What is meant by first element?

Sayantani said:   1 decade ago
When we passing a hole array as argument like:

getArray(int formal[])
{
int i;
for(i=0;i<12;i++)
{
scanf("%d",&formal[i]);
}
return (formal)
}

main
{
int Array[12];

getArray(Array);

for(i=0;i<12;i++)
{
printf("%d\n",Array[i]);
}
getch();
}
--------------------------------------
In getarray(array); ... which technique we are using call by value or call by reference ?

Tanu said:   1 decade ago
Base address same as first address of array element?

Rajab said:   1 decade ago
Write a program that reads values into an array from a file and sorts the data and writes it in a file.

Help me out with this.

Manisha said:   1 decade ago
Find out the value of array.

Diksha said:   1 decade ago
When we pass the array name of a 2-d array as an argument to a function and store the address in a integer pointer in the function, the compiler shows an error "10 C:\Users\DJ\Documents\devc\pointerarray.cpp cannot convert `int (*) [4]' to `int*' for argument `1' to `void display (int*, int, int) ' ".

Compiler- DEV C.


Post your comments here:

Your comments will be displayed after verification.