#include<stdio.h>
main()
{
int arr[]={2, 3, 4, 1, 6};
printf("%u, %u, %u\n", arr, &arr[0], &arr);
return 0;
}
Its Output is:- 1200 1200 1200 I want to know how its answer is 1200?
I want to know how does it work??
#include<stdio.h>
main()
{
int arr[]={2, 3, 4, 1, 6};
printf("%u, %u, %u\n", arr, &arr[0], &arr);
return 0;
}
Its Output is:- 1200 1200 1200 I want to know how its answer is 1200?
I want to know how does it work??
arr &arr[0] and &arr all give the address of the array.
But the address of an array is not necessarily an integer, so your printf causes undefined behaviour.
The correct way would be: printf("%p\n",(void *)arr);
. The actual output depends on your implementation and is most likely meaningless to you for any purpose for C programming.
arr
gives the base address of array (starting memory address of arr
)
&arr[0]
gives the address of first element in arr
which is 1200.
&arr
is the address of the array itself (int arr[]={2, 3, 4, 1, 6};
), so if you do &arr+1
it will points to memory just past the end of the entirety of your array (1200+sizeof(int)*5
).