Pointing to arbitrary location

This is a discussion on Pointing to arbitrary location within the C Programming forums, part of the General Programming Boards category; Hello, How would I assign a pointer an arbitrary random value like 1234. I want to re point the pointer ...

  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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,170
    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.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

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, 11:21 AM
  2. Recursion Revisited again, and again!
    By clegs in forum C++ Programming
    Replies: 93
    Last Post: 12-08-2007, 07:02 PM
  3. instantiated from here: errors...
    By advocation in forum C++ Programming
    Replies: 5
    Last Post: 03-27-2005, 08:01 AM
  4. I need help with templates!
    By advocation in forum C++ Programming
    Replies: 6
    Last Post: 03-26-2005, 08:27 PM
  5. Im so lost at . .
    By hermit in forum C Programming
    Replies: 18
    Last Post: 05-15-2002, 01:26 AM

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