I am very new to working with pointers, and my knowledge of C is pretty small. I am trying to understand pointers. I wrote the following code to print a list of variables (a to f) as follows:
0
1
2
3
4
5
I wrote the following code for this:
#include <stdio.h>
int main(){
int a,b,c,d,e,f;
int *p;
int i;
a = b = c = d = f = 0;
p = &a;
for (i = 0; i < 5; i++){
*p += i;
printf("%d\n", *p);
p++;
}
return 0;
}
The idea was that it works through variables and each increases by an ever-increasing number (i). I assume that when variables are initialized at the same time, they will be placed next to each other in memory. However, I get the following output:
0
1
2
3
-1218283607
If I change the for loop only from 0 to 3 (i <4), it works fine, the printer is 0 1 2 and 3. But when I want to print the variable f, it also doesn't seem to have set it.
, , , , - , , .
.