A literal is an assignment to an explicit value, such as
int i = 4; // i is assigned the literal value of '4'
int j = i // j is assigned the value of i. Since i is a variable,
//it can change and is not a 'literal'
EDIT: As pointed out, assignment itself has nothing to do with the definition of a literal, I was using assignment in my example, but a literal can also be passed into a method, etc.
A literal is a value that has been hard-coded directly into your source.
For example:
string x = "This is a literal";
int y = 2; // so is 2, but not y
int z = y + 4; // y and z are not literals, but 4 is
int a = 1 + 2; // 1 + 2 is not a literal (it is an expression), but 1 and 2 considered separately are literals
SomeMethod("this is another string literal");
bool b = false; // false is a literal, but b is not.
Some literals can have a special syntax, so you know what type the literal is:
// In C#, the 'M' in 10000000M means this is a decimal value,
// rather than int or double.
var accountBalance = 10000000M;
What sets literals apart from variables or resources is the compiler can treat them as constants or perform certain optimizations with code where they are used, because it's certain they won't change. As one example, the in the int a = 1 + 2; snippet above, the compiler probably computes the result is 3 ahead of time and only uses that result in the final compiled code; no addition operation ever takes place at run time.
A literal value is a value, but a value could also be stored in a variable. In the statement
string str = "string literal";
there's a string variable (str) and a string literal. After the statement is executed they both have the same value.
Be aware that in many languages the variable and the literal value don't necessarily even have to be the same type. For example:
int a = 1.0;
The literal value above is a floating point type. The value will be coerced by the compiler to fit into the int variable.
For another example, in the first line of C++ code above the type of a string literal isn't actually the library type string at all. To maintain backwards compatibility with C, string literals in C++ are char arrays.
I have heard string literals used casually to refer to what the C# specification actually refers to as verbatim string literals. A regular string literal allows for the escaping of certain characters (prefixed by a ), like \t for a tab. A verbatim string literal is prepended by @ and processed verbatim, \ has no special meaning.
//regular
string regular = "\thello world";
//verbatim
string verbatim = @"C:\";
//the regular equivalent of this would be "C:\\"
A literal is when you include the value in the source code (as opposed to referencing a variable or a constant). For example:
int result = a + 5; // a is a variable with a value, 5 is a literal
string name = "Jeff Atwood"; // name is a variable initialized
// with the string literal, "Jeff Atwood"
int[] array = new int[] {1, 2, 3}; // C# has array literals (this is actually three
// int literals within an array literal)
If the literal represents some quantity, like a physical constant, it's better to give it a name instead of writing the same literal everywhere you need it. That way, when you are reading the source code, you know what the number means, which is usually more important than its value (which could change anyways).
const int maxUsers = 100;
const double gravitationalAcceleration = 9.8;
Generally, the only numeric literals I use (besides to initialize constants like above) are 0 or 1, and sometimes 2 if I'm skipping every other item in a loop. If the meaning of the number is more important than its actual value (it usually is), its better to name it.
Generally when someone uses the word literal they mean the value is decipherable from the code (text) as shown in many of the examples in other posts.
Another common usage is for values that are converted to immediate values in assembly. These are values that are inserted directly into the machine instruction rather than requiring register loads.
Literals are shorthand notation for values in certain types that language considers so important or fundamental that it has dedicated syntax sugar just for them.
Example of types whose values are often represented by literals:
Here the value Car("BMW", 5) in the type Car is indeed uniquely denoted using a sequence of symbols, however, the value is not represented using a dedicated shorthand literal, but instead uses general (verbose) notional mechanisms for denoting values of any class type.
The term literal is synonymous with terms value, instance, constant, member, and element of a type, but carries a bit of extra meaning that tells us there is a shorthand for writing it down.
I like to think about literals as Egyptian hieroglyphs as opposed to stringing together characters from an alphabet in order to express a concept.