C Programming - Arrays - Discussion
Discussion Forum : Arrays - Yes / No Questions (Q.No. 4)
4.
Are the expressions arr and &arr same for an array of 10 integers?
Answer: Option
Explanation:
Both mean two different things. arr gives the address of the first int, whereas the &arr gives the address of array of ints.
Discussion:
15 comments Page 1 of 2.
Priya said:
1 decade ago
Someone explain this.
Krishma said:
1 decade ago
When I'm running an example of this.. &arr and arr are giving the same value. How?
Dave said:
1 decade ago
Can anyone explain it in depth. not able to get what they r saying..
Ram said:
1 decade ago
Try this
#include<stdio.h>
int main()
{
int arr[2];
printf("%d \n",arr);
printf("%d \n",(arr+1));
printf("%d \n",&arr);
printf("%d \n",(&arr+1));
}
#include<stdio.h>
int main()
{
int arr[2];
printf("%d \n",arr);
printf("%d \n",(arr+1));
printf("%d \n",&arr);
printf("%d \n",(&arr+1));
}
Rupinderjit said:
1 decade ago
@Ram:You are right ,but the one thing here need to be consider is that, it also depends upon the dimensions of an array.you gave example of 1 D array.But problem is for @ D array.
In 2D array,an array in argument acts as a pointer(compiler dependent).so a(a+0) points to 1st row and a+1 points to second row and it's first element.
And &arr gives the address of array of ints(address of last element of an array which is equivalent to base address+size of type * number of elements).
In 2D array,an array in argument acts as a pointer(compiler dependent).so a(a+0) points to 1st row and a+1 points to second row and it's first element.
And &arr gives the address of array of ints(address of last element of an array which is equivalent to base address+size of type * number of elements).
Debendra Kumar kar said:
1 decade ago
Both value will be same only the scaling factor will change.
So out put will be same and the answer will be A as yes.
So out put will be same and the answer will be A as yes.
Teja said:
1 decade ago
arr and &arr are same.
both returns the base address of the arr at any time.
for better understanding execute ram's program.
but for 2D array arr,&arr[0] both returns the same address.
both returns the base address of the arr at any time.
for better understanding execute ram's program.
but for 2D array arr,&arr[0] both returns the same address.
Saffrin said:
1 decade ago
They are same both arr and &arr holding starting address of array.
Tony Joseoh said:
1 decade ago
Considering an Array &arr and arr returns the address of the first element of the array and the result goes same. And the answer is "YES" I believe.
Akshay said:
1 decade ago
Using the name of array directly always gives the base address of array i.e. address of first element in array. also using &arr will also give the address of first element so both the things are same. if someone wants to distinguish between addresses then he should provide position of the array element e.g. &arr[0] or &arr[5].
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers