'Why does Integer pointer when increased by 1 differ from when increased by 2

Would love to understand what is causing the difference in values when increasing Integer pointer by 1 and 2.

So I have the following code

int i1 = 15;
int *iptr = &i1; 

When printing the value for *iptr we obviously expect to get 15 but when now I have increased by 1 i.e

iptr = iptr + 1

When I print out the value I get 0 however when increased by 2 i.e iptr = iptr + 2 I get 1795094656

Why is this the case



Solution 1:[1]

Because you are simply increasing the address value that the pointer iptr points to rather than the value that is stored in that address. To increase or change the value, all you need to do is to use

*iptr = index + 1

And the reason you are getting these strange numbers is that you are accessing random addresses of which values are not known.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1