I'm confused about the datatype of a string literal. Is it a const char *
or a const char
?
String literals are specified by one or more characters enclosed in single quotes. The default data type for string literals is varchar, but a string literal can be assigned to any character data type or to money or date data type without using a data type conversion function.
A string literal with the prefix L is a wide string literal. A string literal without the prefix L is an ordinary or narrow string literal. The type of narrow string literal is array of char .
There are three sets of literal types available in TypeScript today: strings, numbers, and booleans; by using literal types you can allow an exact value which a string, number, or boolean must have.
A string literal is where you specify the contents of a string in a program. Here 'A string' is a string literal. The variable a is a string variable, or, better put in Python, a variable that points to a string. String literals can use single or double quote delimiters.
It is a const char[N]
(which is the same thing as char const[N]
), where N
is the length of the string plus one for the terminating NUL
(or just the length of the string if you define "length of a string" as already including the NUL
).
This is why you can do sizeof("hello") - 1
to get the number of characters in the string (including any embedded NUL
s); if it was a pointer, it wouldn't work because it would always be the size of pointer on your system (minus one).
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