What is the difference between a string and a literal?

What is the type of "I like Comp Sci!"? I am sure it is either a string or a letter, can someone point out the difference between them and help me find the answer

+4
source share
3 answers

A string is a sequence of characters. A literal is data that is entered as part of a program. If you have "I like Comp Sci" entered into your program, then this is a string literal.

+5
source

In most languages, this will be considered both a string and a literal. A string is a set of characters that make up a section of text. A literal is an unconditional constant that is directly injected into your source code. They are not mutually exclusive.

+1
source

A string is a data type, but a string literal is when a string is defined literally usually in quotation marks:

 String myString = "This is a literal string"; 

In the example, String is a type, myString is the name of a variable or link, and the text in quotation marks is a literal string.

0
source

All Articles