I just started learning about pointers and I'm someone who gets stuck in the details. I understand that when we add an integer to a pointer, it offsets the pointer by its size which is 4. Same for another type with size m. But I don't get why the address of first element changes in the following operations.
I did the following operation
#include <stdio.h>
int main()
{
int arr[] = {10,20,30,40,50};
int *ptr = arr;
int i;
for(i=0;i<5;i++)
{
printf("%d\n", ptr);
ptr++;
}
return 0;
}
and got the following as output:
6422016 6422020 6422024 6422028 6422032
but when I changed the loop like this:
for(i=0;i<5;i++)
{
printf("%d\n", ptr+i);
}
The output is this:
6422000 6422004 6422008 6422012 6422016
Why do I get different addresses? I thought at least the first address would be same. Does ptr+i and ptr++ do different things?