These calls of printf
printf("%lf \n",p);
and
printf("%lf \n",p++);
invokes undefined behavior because there is used the wrong conversion specifier "%lf"
(where by the way the length modifier has no effect even when used with object of the type double
) with pointers.
Either you should use the conversion specifier %p
like
printf("%p \n", ( void * )p);
and
printf("%p \n", ( void * )p++);
Or if you want to output addresses as integers you can include headers <stdint.h>
and <inttypes.h>
(the last header already includes the first header and write
#include <stdint.h>
#include <inttypes.h>
//...
printf("%" PRIuPTR "\n", ( uintptr_t )p);
and
printf("%" PRIuPTR "\n", ( uintptr_t )p++);
Pay attention to that according to the C Standard the function main without parameters shall be declared like
int main( void )
Here is a demonstration program.
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
int main( void )
{
double a[] = { 6.0, 7.0, 8.0, 9.0, 10.0 };
const size_t N = sizeof( a ) / sizeof( *a );
double *p = a;
printf( "%p", ( void * )p );
printf( " <-> %" PRIuPTR "\n", ( uintptr_t )p );
for ( size_t i = 0; i < N; i++ )
{
printf( "%p", ( void * )p );
printf( " <-> %" PRIuPTR "\n", ( uintptr_t )p++ );
}
}
The program output is
00AFFE40 <-> 11533888
00AFFE40 <-> 11533888
00AFFE48 <-> 11533896
00AFFE50 <-> 11533904
00AFFE58 <-> 11533912
00AFFE60 <-> 11533920