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.
Vaishu said:
7 years ago
Please explain me clearly to get the answer.
(1)
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.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers