1 for example, we can use it to refer to the same array s that we defined above What's the difference between char* name which points to a constant string literal, and const char* name We do this by setting our char* to the memory location of the first element of s
The & operator gives us the memory location of s[0] Thus making s[0] = 'j' Here is a shorter way to write the above
// s points to an array of 5 chars modify(&s) // s now points to a new array of 10 chars free(s) } you can also use char ** to store an array of strings However, if you dynamically allocate everything, remember to keep track of how long the array of strings is so you can loop through each element and free it.
As the initializer for an array of char, as in the declaration of char a [] , it specifies the initial values of the characters in that array (and, if necessary, its size) Is an array of chars, initialized with the contents from test, while char *str = test Is a pointer to the literal (const) string test The main difference between them is that the first is an array and the other one is a pointer
Technically, the char* is not an array, but a pointer to a char Similarly, char** is a pointer to a char* Making it a pointer to a pointer to a char Char *array = one good thing about music
If you are printing a single character, you use the %c format specifier, and the matching argument should be a character (ie 50 the difference between char* the pointer and char[] the array is how you interact with them after you create them If you are just printing the two examples, it will perform exactly the same They both generate data in memory, {h, e, l, l, o, /0}
The difference here is that char *s = hello world Char s[] = hello world