what (char*)data and (int*)data means |
That means typecasting. you can read
http://www.cplusplus.com/doc/tutorial/typecasting.html
anyway let me explain that statement for you:
1 2 3 4 5 6 7
|
void increase (void* data, int psize) // line 1
{
if ( psize == sizeof(char) )
{
char* pchar; // line 2
pchar=(char*)data; // line 3
++(*pchar); } // line 4
| |
oky , you agree that , inside this function's scope , data is type of
void *
void * is a void pointer. you can see it it definition in the line 1 .
in the line 2 you can see another definition of the pchar which is type
char *
so . In the C++ , strongly typed language , the "void *" and the
"char *" is different. It's like int and long. So that's why we need
some typecasting. so we write ,
pchar=(char*)data;
That means you convert a void pointer to a char pointer. and then you can use it like a char pointer . In the line number 3 you have use it as a
char pointer.
++(*pchar);
Now got clear ?
well for the next question :
I just don't see where it changes the value. |
well nothing is hiding by the compiler. Nothing magic is going behind the screen. If you are using the visual studio IDE , then you can just debug
your program and trace how line by line executing the program. Using the
watch window you can inspect each variables. And everything will be crystal
clear after that.
--
I am just yet a newbie , please tell me if I suggesting bad , I will be quite and listen.