For instance
what type of data type is the string "middleName" ?
Thanks in advance
Five answers:
modulo_function
2010-10-09 12:50:37 UTC
I'm surprised that nobody gave you a very good answer.
There's two ways to represent strings:
1) C-strings
These are char arrays. Of course a char is a data type.
2) the class
C++ also has a class In this case a string is an object of this class.
Cubbi
2010-10-10 02:24:11 UTC
string is the name of a data type in C++ (to be pedantic, it is an typedef alias to the template specialization std::basic_string)
however "middleName" does not name a type. It is a string literal, which is an instruction to the compiler to create a nul-terminated array of char in the read-only section of the program's data segment, initialized with the characters "middleName" with NUL (character '\0') added at the end. When a string literal is used in an expression, it evaluates to the pointer to the first character in the array. That pointer has the type const char*.
Joe L
2010-10-09 19:19:39 UTC
It's a char array in native C++ (char *). However, many class libraries will include a String class of some type that will help you to extract substrings, etc.
elex
2010-10-09 19:21:41 UTC
Yes and know.... The C++ specification does not contain the keyword string, as I remember However you can create your own data type though classes and name it string. :D
2010-10-09 19:16:59 UTC
Its a char. Example :
char *mn = "middleName";
ⓘ
This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.