Please tell me what does the parameter (char* s) means?? Can it accept an array of characters or it will just accept pointers. Please also tell how can i make this to accept an array of strings and then dynamically assign memory depending on the length of the string.
Share
Technically, it’s a pointer to a single
charvariable. However, it can also be the pointer to the first element of an array ofcharvalues. You can increment and decrement the pointer to move through the string (s++ors--) as long as you don’t go beyond the ends.You can also use indexing without changing the pointer, such as
s[14] = 'a';.Using it as a pointer to a
chararray is usually the case when you’re dealing with C-style strings.In addition, a
chararray will decay to the pointer to its first element under many circumstances, such as passing to a function:For an array of strings in C, you would use
char **, a pointer to and array ofcharpointers.For C++, you should probably ditch
charpointers (for strings) and pass-by-pointer altogether. Usestd::stringand reference types.