Mega Code Archive

 
Categories / C++ Tutorial / Data Types
 

Copying a string using array notation

#include <iostream> using std::cout; using std::endl; void copy1( char *, const char * ); int main() {    char string1[ 10 ];    char *string2 = "Hello";    copy1( string1, string2 );    cout << "string1 = " << string1 << endl;    return 0; } void copy1( char * s1, const char * s2 ) {    for ( int i = 0; ( s1[ i ] = s2[ i ] ) != '\0'; i++ )       ; } string1 = Hello