Copy a string: Difference between revisions

→‎{{header|C}}: Another reference to an existing string
(→‎{{header|C++}}: Copying from std::string to C string and back)
(→‎{{header|C}}: Another reference to an existing string)
Line 61:
strncpy(dst, src, 80);
dst[79] = 0;
 
=== Creating another reference to an existing string ===
const char* src = "Hello";
const char* dst;
dst = src; /* now dst refers top the same string as src */
 
The same works for mutable strings, e.g.
char[] src = "Hello";
char* dst;
dst = src;
dst[1] = 'a'; // Now src contains "Hallo"
 
=={{header|Objective-C}}==
973

edits