The question is not about what happens, but why it happens.
//for printf
#include <stdio.h>
//for malloc
#include <stdlib.h>
int main(void)
{
int *pointy = malloc(4 * sizeof(int));
pointy[0] = 22;
pointy[1] = 23;
pointy[2] = 24;
printf("%p meow %i meow %p meow %p meow %p meow %p", pointy, sizeof(int), &(pointy[1]), (pointy + 1 * sizeof(int)), (pointy + 1), ((int)pointy + 1 * sizeof(int)));
//deallocating the space
free(pointy);
}
Output : 00000000000A1400 meow 4 meow 00000000000A1404 meow 00000000000A1410 meow 00000000000A1404 meow 00000000000A1404
So, pointy+1 adds 4 bytes to pointy. I guess that is because pointy is of type "int*" and the addition happens similar to the logic:
(int*) pointy + (int*) 1
But it isn't working the same way like adding an int to a double ( which would yield a double result). The compiler doesnt actually let me cast " 1 " to type " int * " if I try to do so in this scenario... So I think there are more reasons beneath it. And googling didn't work, so I'm asking it here.
Please provide a detailed explanation, and I'll be thankfull.
The lower-level explanation, the better. I also would like to learn if you have any recommendations on learning fundamentals of programming with a COMPLETE * bottom-up * approach