char is a primitive data type whereas String is a class in java. char represents a single character whereas String can have zero or more characters. So String is an array of chars. We define char in java program using single quote (') whereas we can define String in Java using double quotes (").
We can create a character pointer to string in C that points to the starting address of the character array. This pointer will point to the starting address of the string, that is the first character of the string, and we can dereference the pointer to access the value of the string.
char* means a pointer to a character. In C strings are an array of characters terminated by the null character.
Now, let's start with the char* piece. This is a pointer to a char. It is not necessarily pointing to the beginning or middle of a string or array. It might be just pointing to a single character.
I have a C++ string
. I need to pass this string to a function accepting a char*
parameter (for example - strchr()
).
a) How do I get that pointer?
b) Is there some function equivalent to strschr()
that works for C++ strings
?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With