-
Changing memory address
I would like to know how to get and/or change the memory address of e.g: "int i".
so if to say it is (hex): "22ff68" and i would like to change it to e.g (hex): "22ffa4"
how would i do that? -Btw i only know how to get the memory address of what addresses pointers has in their memory.
-
Well, your question is kind of wierd, but you might want pointer arithmetic.
http://c-faq.com/~scs/cclass/notes/sx10b.html
http://www.cs.umd.edu/class/spring20...p/pointer.html
Do you actually want 'i' to be somewhere else (why?) or do you just want to point to a different location?
-
Cause "int i"'s memory gets in the way, if i would like to have another variable's "int _4zz"
+1 in memory address so work you see, i want to use:
"*_4zz,(*_4zz+1),(*(_4zz+2),*(_4zz+3)"and so on..
But "int i" has the memory address of "(*_4zz+1)"so i would like to change it.
I dont want to stop using "*(_4zz+1)"cause it is good for looping e.g
Code:
for(i=0;i<5;i++)printf("%d\n",*(_4zz+i);
Now that i think more about it, i could change the pointer variable "*_4zz" memory address instaid maybe it would be easier (or just possible)?
Anyways... i think the solution would be pointers cause they handle memory addresses right? :)
Though it would be nice if i could just write it like this: &i = 22ff68, or &i = 2293608.
Like in "the memory address of 'int i' is equal to this"
-
Yes, that's called pointer arithmetic, good thinking. *(_4zz + i) is the same thing as the array notation _4zz[i], the c-faq explains that.