Thread: pointer-memory addresses

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

    Question pointer-memory addresses

    What address in memory wil be assigned to the following:

    float *floatptr;

    floatptr = 100;

    floatptr = +- 8;

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Code:
    #include <stdio.h>
    int main(void)
    {
    	float *floatptr; 
    	
    	floatptr = 100; 
    	printf("pointer address is %p\n", floatptr);
    	floatptr = +- 8;
    	printf("pointer address is %p\n", floatptr);
    	return(0);
    }
    Output from compiler:
    Code:
    Borland C++ 5.5 for Win32 Copyright (c) 1993, 2000 Borland
    E:\AAPgm\MyProg\C\junk\junk6.c:
    Warning W8069 E:\AAPgm\MyProg\C\junk\junk6.c 6: Nonportable pointer conversion in function main
    Warning W8069 E:\AAPgm\MyProg\C\junk\junk6.c 8: Nonportable pointer conversion in function main
    Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland
    Output from program when run:
    Code:
    E:\AAPgm\MyProg\C\junk>junk6
    pointer address is 00000064
    pointer address is FFFFFFF8
    You don't assign hard coded values to pointer in this manner (with the exception of NULL).
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  3. #3
    *
    Guest
    > You don't assign hard coded values to pointer in this manner (with the exception of NULL).

    Actually, that's not absolute. Obviously, there is a time and place to actually assign hard-coded values to a pointer. For example, if you are accessing a ROM address, or a known trap-address.

    Normally, however, a pointer's value (it's contents) is established when you allocate memory to go with it (for example, when using malloc()).

    Or, as Hammer stated, when you initialize the variable to a known, state, like nil.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 03-23-2009, 03:44 PM
  2. pointers
    By xixpsychoxix in forum C Programming
    Replies: 4
    Last Post: 10-02-2008, 03:31 PM
  3. Question regarding Memory Leak
    By clegs in forum C++ Programming
    Replies: 29
    Last Post: 12-07-2007, 01:57 AM
  4. Could somebody please help me with this C program
    By brett73 in forum C Programming
    Replies: 6
    Last Post: 11-25-2004, 02:19 AM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM