Three species of strings 1. Char Str [] 2. Char * str3. Static "Hello, World!"
1.char str [] = "Hello, World!" STR [0] = 'a' // can be 2.char * str; str = "Hello, World!" // STR [0] = 'a'; / / No 3.char * str = new char [13]; str = "Hello, World!" Str [0] = 'a'; // No 4.char * str = new char [13]; strcpy (Str, "Hello, World!"); STR [0] = 'a'; // can 5.char * str = new char [13]; str = "hello!"; strcpy (str, "hello, world ! "); STR [0] = 'a'; // No reason: STR [] is assigned a set of space, which stores each character * STR, indicates this static string, does not modify * STR Assigned space, use strcpy, point to characters for each space, modify the storage of some characters
Str [], * strstr [i], address of an element & STR [i], address void * of an element Void * corresponds to Str, or & Str [i]
COUT is a pointer STRCPY, MEMCPY, which can output without allocation space, must first allocate space Memcpy (Void * Dest, Void * src) DEST must first assign space SRC to do not assign space first
Char * STR1, * STR2, * STR3, * STR4; STR1 = New char [20]; str2 = new char [20]; str3 = "hello, world!"; str4 = str3; memcpy (str1, str3, 13) Memcpy (STR2, STR4, 13); // is all possible
Struct ABC {Int A; INT B;}; ABC * A1, * A2; A1 = (ABC *) Malloc (SIZEOF (ABC)); // must be this A1-> a = 1; a1-> b = 1; A2 = (abc *) Malloc (SizeOf (ABC)); Memcpy (A2, A1, SIZEOF (ABC));
Char * str ... memcpy (str, ...) char str [].. Memcpy (Str, ...) char Str []............................. void *) str, ..) Struct str ... memcpy (& str, ..)