Thread: Pointing to arbitrary location

  1. #1
    Registered User
    Join Date
    Jul 2007
    Posts
    43

    Pointing to arbitrary location

    Hello,

    How would I assign a pointer an arbitrary random value like 1234. I want to re point the pointer I don't want to change the value it is pointing to.

    I tried and cant really get much to compile. I got this to compile but it doesn't work right:

    int *a=0;
    int b;

    for(b=0;b<1234;b++)
    a++;

    I was thinking I could create two pointers and point one to the other and reassign that way but I cant get it to compile like this:

    int *a;
    int *b;
    b=&a;
    *b=0;

    Any help appreciated.

    Sean

  2. #2
    Registered User
    Join Date
    Jul 2007
    Posts
    43
    I got it figured out. Use int **a; to point to a pointer

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by elmutt View Post
    int *a;
    int *b;
    b=&a;
    *b=0;
    This won't compile... Or shouldn't, at the very least. And if it does, it will crash.
    And what you actually do is:
    Code:
    int* p = (int*)1234;
    Not that it will do you any good...
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Read an arbitrary memory location?
    By xuftugulus in forum Linux Programming
    Replies: 4
    Last Post: 02-29-2008, 12:21 PM
  2. Recursion Revisited again, and again!
    By clegs in forum C++ Programming
    Replies: 93
    Last Post: 12-08-2007, 08:02 PM
  3. instantiated from here: errors...
    By advocation in forum C++ Programming
    Replies: 5
    Last Post: 03-27-2005, 09:01 AM
  4. I need help with templates!
    By advocation in forum C++ Programming
    Replies: 6
    Last Post: 03-26-2005, 09:27 PM
  5. Im so lost at . .
    By hermit in forum C Programming
    Replies: 18
    Last Post: 05-15-2002, 01:26 AM