pointers... need reassurance I'm understanding things correctly
Hello guys, I've been working on a tutorial this morning and I believe I'm on the right track, I'm just looking for a 'yay or nay' as to if this makes sense or not.
here's my code...
Code:
#include <stdio.h>
char mem[20]; // assume mem is at base address 2000
int x;
int val1 = 0 ;
int val2 = 1 ;
char *ptr;
int main (void) {
ptr = &mem[val1]; // get the address of array element val1 within mem
printf ("base address (which can be considered as 2000) %d\n", mem); //my addition...prints initial base address
for (x = 0; x < 5; x++) {
*ptr = 'A' + x + val2;
printf ("address %d\n", ptr); //my addition...this prints the address of the element you're currently at
printf ("value %d\n", *ptr); //my addition...this prints what is contained inside that element
ptr++;
}
getchar (); //my addition...window won't dissappear until hitting 'enter'
return 0;
}
I have added all the printf's in order to see what's going on.
the output I receive when executing is as follows:
Code:
base address (which can be considered as 2000) 4202784
address 4202784
value 66
address 4202785
value 67
address 4202786
value 68
address 4202787
value 69
address 4202788
value 70
I am being asked to state the 5 addresses that will be written to, and the value put into memory at that location.
assuming I've used 'printf' in the correct fashion,
can I then assume that my 5 addresses and values are:
2000 (value 66)
2001 (value 67)
2002 (value 68)
2003 (value 69)
2004 (value 70)
...(being that I can't set the base address, I let windows choose a different number to represent 2000)
Thanks in advance,
Just need to to verify what I'm doing makes sense!