Trouble Understanding Void Pointer

Hi everyone, sorry to ask another question that seems so simple, but I really can't figure this one out. I'm reading about Void Pointers in "The C++ Language Tutorial" and I can't understand what this function does:

void increase (void* data, int psize)
{
if ( psize == sizeof(char) )
{ char* pchar; pchar=(char*)data; ++(*pchar); }
else if (psize == sizeof(int) )
{ int* pint; pint=(int*)data; ++(*pint); }
}

Does anyone have time to explain it to me? I understand up to
char* pchar;

It's declaring a char pointer with the indentifier pchar, right? And after that I get lost.
That is badly formatted, here is the code in a more readable format with lines commented:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void increase (void* data, int psize)
{
    if ( psize == sizeof(char) ) // check if the type 'data' is pointing to is char
    {
        char* pchar; // create a new pointer to char
        pchar=(char*)data; // assign it to the position pointed by data
        ++(*pchar); // increase the value at that position (this will affect the first byte at data)
    }
    else if (psize == sizeof(int) ) // do the same thing but with int
    {
        int* pint;
        pint=(int*)data;
        ++(*pint); // the result of this depends on the size of an int and on the endianness of the computer
    }
}
Last edited on
Okay, so these two statements:

++(*pchar);

++(*pint);


Are increasing the values pointed to by *pchar and *pint?
I understand now. Went and experimented a little. Thx for all the help!
Topic archived. No new replies allowed.