strcpy copies src to dest stopping after the terminating null-character is copied.
src should be null-terminated!
dest should have enough memory space allocated to contain src string.
Return Value: returns dest
copy ctors calling
call functions by value:
1 2 3
voidroster( Person ); // declare function Person child( "Ruby" ); // create object roster( child ); // call function
C++
initialization:
1 2 3 4 5
//normal initialization Person baby_a("Fred"); // these use the copy ctor Person baby_b = baby_a; Person baby_c( baby_a );
C++
function return:
1 2 3 4 5 6 7
Person captain(){ Person player("George"); return player; } ... Person who(""); ...
C++
Avoid copy ctor?
Compilers can “optimize out” copies when safe!
1 2 3 4 5 6 7 8
Person copy_func( char *who ){ Person local( who ); local.print(); return local; // copy ctor called! } Person nocopy_func( char *who ){ returnPerson( who ); } // no copy needed!