A value directly written into the source code of a computer program (as opposed to an identifier like a variable or constant). Literals cannot be changed. Common types of literals include string literals, floating point literals, integer literals, and hexidemal literals. Literal strings are usually either quoted (") or use an apostrophe (') which is often referred to as a single quote. Sometimes quotes are inaccurately referred to as double quotes.
Languages Focus: Literals
In addition to understanding whether to use a quote or apostrophe for string literals, you also want to know how to specify and work with other types of literals including floating point literals. Some compilers allow leading and trailing decimals (.1 + .1), while some require a leading or trailing 0 as in (0.1 + 0.1). Also, because floating point literals are difficult for compilers to represent accurately, you need to understand how the compiler handles them and how to use rounding and trimming commands correctly for the nature of the project your are coding.
VB.Net Literals
String literals are quoted as in "Prestwood". If you need to embed a quote use two quotes in a row.
To specify a floating point literal between 1 and -1, preceed the decimal with a 0. If you don't, the compiler will auto-correct your code and place a leading 0. It will change .1 to 0.1 automatically. Trailing decimals are not allowed.
Syntax Example: Console.WriteLine("Hello")
Console.WriteLine("Hello ""Mike"".")
'Does VB.Net evaluate this simple
'floating point math correctly? No!
If (.1 + .1 + .1) = 0.3 Then
MsgBox "Correct"
Else
MsgBox "Not correct"
End If
The following are practice certification questions with answers highlighted. These questions were prepared by Mike Prestwood and are intended to stress an important aspect of this KB post. All our practice questions are intended to prepare you generally for passing any certification test as well as prepare you for professional work.