Thread: Memory Addresses

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    2

    Question Memory Addresses

    Hello all
    How do I assign a variable to a specific memory address?

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Code:
     int address = 1000;
     int * ptr = (int*)address;
     *ptr = 175; //... cross fingers :D ...
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User xds4lx's Avatar
    Join Date
    Nov 2001
    Posts
    630
    Originally posted by Sebastiani
    Code:
     int address = 1000;
     int * ptr = (int*)address;
     *ptr = 175; //... cross fingers :D ...
    hehehe

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    You could just do this:

    Code:
    int *ptr = (int *)02400000; //yes this is an octal number, I never use them.
    *ptr = ~*ptr;
    
    // Should be in the video card range somewhere.
    But you shouldn't be doing this anyway. I saw this exact question on the boards earlier. Doing this is not a good idea if you don't know what you are doing. By virtue of the fact that you don't know how to do this I'd say that you shouldn't be doing this sort of thing.

  5. #5
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    >>*ptr = ~*ptr;
    What is this line used for, is the ~ the compliment.
    So how does it work?
    Last edited by ammar; 12-10-2002 at 04:48 AM.
    none...

  6. #6
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>I saw this exact question on the boards earlier.
    http://www.cprogramming.com/cboard/s...threadid=30224
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  7. #7
    Registered User
    Join Date
    Oct 2002
    Posts
    160
    What's the difference betwem
    Code:
    int address = 1000;
    int *ptr = (int*)address;
    and
    Code:
    int address = 1000;
    int *ptr = address;
    - It may be because I haven't yet used CAST, but please explain.

    *EDIT*

    Furthermore I don't get what the point is about this:
    int *ptr = (int *)02400000;
    Last edited by Zahl; 12-10-2002 at 08:44 AM.
    Well english isn't my first language, (it's instead a useless language called danish which only 5 milion people speak!!) so if you think my grammar SUCKS (it does by the way) than you're more then welcome to correct me.
    Hell I might even learn something

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how can know in memory someone addresses in free list
    By 0000000009 in forum C Programming
    Replies: 8
    Last Post: 10-17-2005, 12:35 AM
  2. help with displaying memory addresses
    By RancidWannaRiot in forum C++ Programming
    Replies: 7
    Last Post: 09-02-2005, 09:40 PM
  3. Memory allocation and deallocation
    By Micko in forum C++ Programming
    Replies: 3
    Last Post: 08-19-2005, 06:45 PM
  4. Editting Memory Addresses?
    By Dae in forum C++ Programming
    Replies: 7
    Last Post: 07-03-2005, 07:07 PM
  5. Pointer's
    By xlordt in forum C Programming
    Replies: 13
    Last Post: 10-14-2003, 02:15 PM