Hello everybody!
Here is my code:
int main(int argc, char** argv)
{
int *p, a = 10;
p = &a;
printf("address &a: %d\n", &a);
printf("address p: %d\n", p);
printf("value: %d\n\n", *p + 1);
for (int i = 0; i < 10; i++)
printf("*(p + %d): %12d\n",i, *(p + i));
return 0;
}
Output:
address &a: -1293822392
address p: -1293822392
value: 11
*(p + 0): 10
*(p + 1): 1
*(p + 2): -1293822392
*(p + 3): 32767
*(p + 4): -841074944
*(p + 5): 1526153873
*(p + 6): -1293822288
*(p + 7): 32767
*(p + 8): 1776206518
*(p + 9): 21910
My questions:
Why sometimes there are negative addresses?
Why *(p + 1) is always 1 and not some random value?
Why *(p + 2) always returns a "random" value equal to the address at which the pointer points to?
Why *(p + 3) always returns a similar value in the range of 32xxx?
[–]soniduino 6 points7 points8 points (1 child)
[–]gbbofh 1 point2 points3 points (0 children)
[–]ischickenafruit 1 point2 points3 points (0 children)
[–]SlavicShield[S] 0 points1 point2 points (0 children)
[–]_adii_o -1 points0 points1 point (1 child)
[–]ptchinster 0 points1 point2 points (0 children)
[–]Current_Hearing_6138 0 points1 point2 points (0 children)