Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does the pointer assignment in strcpy work?

Tags:

c

pointers

I'm looking at a strcpy example where they increase the value of a pointer, and assign it in 1 line, like this:

*ptrA++ = *ptrB++;

I know that the value where the pointer is pointing to in the char array is increased, and the contents is copied.

does c do something like

*ptrA = *ptrB;
ptrA++;
ptrB++;

in the background ?

like image 744
zlack Avatar asked Aug 03 '26 03:08

zlack


1 Answers

Yes it does, remember that the postfix ++ means return the value before the increment. So *ptrA++ increments ptrA but returns the dereference of of ptrA before the increment.

like image 100
Ramónster Avatar answered Aug 05 '26 19:08

Ramónster