Results 1 to 6 of 6

Thread: Don't know about void pointer

  1. #1
    Join Date
    Dec 2009
    Posts
    41

    Don't know about void pointer

    Hello Guys,

    I have one query to ask you and which is related to the pointer. Basically pointers are used to access the memory location of the variable. I have little bit knowledge about the wild pointer, but don't know anything about the 'void pointer'. It's very strange type of pointer for me. Does anybody aware about 'Void pointer'? if yes then please share you knowledge with me. Your help would be appreciable.

  2. #2
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Don't know about void pointer

    The void pointer is completely different than wild pointer, in this pointer we can assign any type of datatype. The void pointer used to pointe towards the raw data. And because of this the compile doesn't get any idea about the assignment of the void pointer. The void pointer works with 'unspecified type'. This can be done without any specific type casting of variable's datatype. We mostly use void pointer than wild pointer.

  3. #3
    Join Date
    Apr 2008
    Posts
    1,948

    Re: Don't know about void pointer

    I have one example of void pointer which is given belwo. Please study this program carefully:
    Code:
    void increaseF (void* dataF, int psizeF)
    {
      if ( psizeF == sizeof(char) )
      { char* pcharF; pchar=(char*)data; ++(*pchar); }
      else if (psizeF == sizeof(int) )
      { int* pint; pint=(int*)data; ++(*pint); }
    }
    int main ()
    {
      char a = 'x';
      int b = 1602;
      increaseF (&a,sizeof(a));
      increaseF (&b,sizeof(b));
      cout << a << ", " << b << endl;
      return 0;
    }

  4. #4
    Join Date
    May 2008
    Posts
    2,012

    Re: Don't know about void pointer

    A void pointer comprises limited functionality. It is very useful when we used to cast the pointer into the other type. This type of opinter also referred as "generic pointer". The C provides an operator to retrieve the address of a variable, so that it can be stored in a pointer, which will then point to the variable. By using the void pointer, we have access to the data, both reading and writing, just as if we had worked directly on the variable pointed.

  5. #5
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Don't know about void pointer

    When we apply void pointer, the operator * is then the dereference operator, sometimes called indirection operator. Since pointers are part of the C language it is almost impossible to understand without practice, writing a function whose role is to share the values of two variables passed as parameters. We can not change the fact that the passing parameters is by copying it is set by the C standard, and can not be otherwise.

  6. #6
    Join Date
    May 2008
    Posts
    2,297

    Re: Don't know about void pointer

    Example of void pointer:
    int nValuer;
    float fValuer;

    struct akh
    {
    int nValue;
    float fValue;
    };

    akh Value;

    void *pVoidr;// void pointer
    pVoidr = &nValue;
    pVoidr = &fValue;
    pVoidr = &sValue;

Similar Threads

  1. Changing Stylus pointer to normal Pointer in Tablet PC
    By Kelley in forum Portable Devices
    Replies: 3
    Last Post: 21-06-2011, 07:22 PM
  2. Problem in void ***m
    By Luis-Fernando in forum Software Development
    Replies: 4
    Last Post: 09-02-2010, 08:14 PM
  3. How to use void pointer to generate 2D Array in c++
    By Conraad in forum Software Development
    Replies: 4
    Last Post: 06-02-2010, 05:14 PM
  4. Differentiation between void pointer and null pointer
    By Ram Bharose in forum Software Development
    Replies: 5
    Last Post: 18-01-2010, 12:11 PM
  5. void f(int val) vs void f(int & val)
    By ANSEL in forum Software Development
    Replies: 3
    Last Post: 07-11-2009, 09:10 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,256,137.25888 seconds with 17 queries