Tuesday, August 31, 2010

++ / -- and pointers operator *

++ is executed first comparing with *.

So we have to use ++ (*p)

Eg, consider strcpy() function.


char *strcpy(char *dest, const char *src)
{
char *save = dest;
while(*dest++ = *src++);
return save;
}
So here first thing that is happening in while loop is dest and src are incremented by 1
Than they are referenced by *
Then equated and finally loop moves on until it gets '\0'..i.e null

No comments:

Post a Comment