Link to home
Start Free TrialLog in
Avatar of markdot
markdot

asked on

C++ strcpy

void main()
{
      char s[100]={'a','b','c','d','e','f','g'};
      strcpy(s+4,s+3);
      cout<<s<<endl;
      return;
}
I thought it should be abcddefg, but it is abcdddfg. Can you explain in detail?
Avatar of sunnycoder
sunnycoder
Flag of India image

The behavior is undefined
http://www.opengroup.org/onlinepubs/000095399/functions/strcpy.html
If copying takes place between objects that overlap, the behavior is undefined.
Avatar of markdot
markdot

ASKER

Then, how can we shift the sub-string "defg"  in char s[100]={'a','b','c','d','e','f','g'}?
ASKER CERTIFIED SOLUTION
Avatar of sunnycoder
sunnycoder
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of markdot

ASKER

That is what I need!