Reputation: 93
What is the type of "I like Comp Sci!"? I'm pretty sure its either a string or a literal, can anyone point out the difference between the two and help me find the answer
Upvotes: 4
Views: 1140
Reputation: 8772
In most languages, it would be considered both a string and a literal. A string is a collection of characters that make up a section of text. A literal is an unconditional constant which is directly entered into your source code. They are not mutually exclusive.
Upvotes: 1
Reputation: 86708
A string is a sequence of characters. A literal is data that's typed in as part of the program. If you have "I like Comp Sci"
typed into your program, then it's a string literal.
Upvotes: 5
Reputation: 1785
A string is a data type, but a string literal is when a string is defined literally usually in quotes:
String myString = "This is a literal string";
In the example String is the type, myString is a variable or reference name, and the text in quotes is a literal string.
Upvotes: 0