Changing memory address

This is a discussion on Changing memory address within the C Programming forums, part of the General Programming Boards category; I would like to know how to get and/or change the memory address of e.g: "int i". so if to ...

  1. #1
    1 == 1 tzpb8's Avatar
    Join Date
    Jul 2006
    Posts
    36

    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.

  2. #2
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    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?

  3. #3
    1 == 1 tzpb8's Avatar
    Join Date
    Jul 2006
    Posts
    36
    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"
    Last edited by tzpb8; 07-26-2006 at 09:54 AM.

  4. #4
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 10
    Last Post: 09-04-2008, 01:27 PM
  2. Assignment Operator, Memory and Scope
    By SevenThunders in forum C++ Programming
    Replies: 47
    Last Post: 03-31-2008, 06:22 AM
  3. Pointer to specific memory address
    By elnerdo in forum C++ Programming
    Replies: 10
    Last Post: 05-19-2006, 07:35 AM
  4. Memory address?
    By Munkey01 in forum C++ Programming
    Replies: 4
    Last Post: 02-01-2003, 08:04 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21