Value is not being stored at correct location
I am trying to allocate dynamic memory for five integer to store value from 0 to 4
as shown
00DE2AB4 = 0
00DE2AB8 = 1
00DE2ABC = 2
00DE2AC0 = 3
00DE2AC4 = 4
Code:
#include<stdio.h>
#include<stdlib.h>
int main ()
{
int *x = malloc(5 * sizeof(x));
int i = 0;
for ( i = 0; i < 5; i++)
{
x++;
printf( "Value of x[%d] = %p\n", i, x );
}
printf("\n");
for ( i = 0; i < 5; i++)
{
*x = 1;
*x++;
printf("Value %d store at address %p\n", *x , i);
}
return 0;
}
Value of x[0] = 00022AB4
Value of x[1] = 00022AB8
Value of x[2] = 00022ABC
Value of x[3] = 00022AC0
Value of x[4] = 00022AC4
Value 902931021 store at address 00000000
Value 134222834 store at address 00000001
Value 1970037078 store at address 00000002
Value 959520869 store at address 00000003
Value 808596793 store at address 00000004
Program output show that memory has been allocated for five integer but value are not being stored at address. Can anyone point out what is reason for this ?