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 2 of 2.
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).
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));
}
Dave said:
1 decade ago
Can anyone explain it in depth. not able to get what they r saying..
Krishma said:
1 decade ago
When I'm running an example of this.. &arr and arr are giving the same value. How?
Priya said:
1 decade ago
Someone explain this.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers