Could anyone explain me, how these two *(ptr + i) = i; and *(ptr + (i - 1); process to get the result ? I don't understand that syntax, could anyone tell me in clearer way?
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i;
int *ptr;
int number;
printf("How many ints would you linke to store?");
scanf("%d", &number);
ptr = malloc(number * sizeof(int));
if (ptr != NULL)
{
for (i = 0;i < number;i++)
{
*(ptr + i) = i;
}
for (i = number;i > 0;i--)
{
printf("%d\n", *(ptr + (i - 1)));
}
free(ptr);
return 0;
}
else
{
printf("\nMemory allocation failed - not enough memory.\n");
return 1;
}
}