I have a pointer to integer array of 10. What should dereferencing this pointer give me?
Eg:
#include<stdio.h>
main()
{
int var[10] = {1,2,3,4,5,6,7,8,9,10};
int (*ptr) [10] = &var;
printf("value = %u %u\n",*ptr,ptr); //both print 2359104. Shouldn't *ptr print 1?
}
What you dereference is a pointer to an array. Thus, dereferencing gives you the array. Passing an array to printf (or to any function) passes the address of the first element.
You tell
printfthat you pass it anunsigned int(%u), but actually what is passed is anint*. The numbers you see are the addresses of the first element of the array interpreted as an unsigned int.Of course, this is undefined behavior. If you want to print an address, you have to use
%pand pass avoid*.