A pointer that can be used to point anything

This is a discussion on A pointer that can be used to point anything within the C Programming forums, part of the General Programming Boards category; Hi all: Can I declare a pointer as: void *ptr = NULL; and later use it to point at any ...

  1. #1
    Registered User
    Join Date
    Sep 2008
    Posts
    26

    Question A pointer that can be used to point anything

    Hi all:

    Can I declare a pointer as:

    void *ptr = NULL;

    and later use it to point at any type of data?

    Cheers

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, a void * can be used to point to anything. However, bear in mind that _YOU_ will have to know what it points to.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Sep 2008
    Posts
    26

    Smile

    Cheers.
    Thank you for your help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 0
    Last Post: 03-20-2008, 07:59 AM
  2. What is a virtual function pointer?
    By ting in forum C++ Programming
    Replies: 4
    Last Post: 03-05-2008, 01:36 AM
  3. 6 measly errors
    By beene in forum Game Programming
    Replies: 11
    Last Post: 11-14-2006, 10:06 AM
  4. Compiler "Warnings"
    By Jeremy G in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 04-24-2005, 01:09 PM
  5. Replies: 2
    Last Post: 01-29-2003, 02:32 PM

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