There's a strange code here:
const double a[] = {0,1,2,3,4};
int main()
{
double *p = a;
printf("%f\n",p[2]); //2.000000
printf("%f\n",p); //2.000000
}
It return 2.000000 ,why?
There's a strange code here:
const double a[] = {0,1,2,3,4};
int main()
{
double *p = a;
printf("%f\n",p[2]); //2.000000
printf("%f\n",p); //2.000000
}
It return 2.000000 ,why?
The code
printf("%f\n",p);
causes undefined behavior. To print an address (a pointer) which is the type an array name decays to when passed as function argument, you need to
%p
conversion specifier.(void *)
.