sales@scenomics.com +1 650 396 9674

Literal Expressions

Literal expressions are composed of constant data.

Details

Details are as follows:

  • Literal expressions cannot be used in pass by reference function parameters.
  • Literal expressions cannot be used as an l-value in an assignment expression.
  • Literal expressions of integral type accept decimal notation, hexadecimal notation, and octal notation.
  • Some characters in string literal expressions require escape characters.

Examples

The following example declares an integer variable named x and initializes it to the literal expression 10.

int x = 10;

The following example declares an integer variable named y and initializes it to the literal expression 0xA using hexadecimal notation. 0xA is equal to the decimal number 10.

int y = 0xA;

The following example declares a string variable named s and initializes it to the literal expression Hello World.

string s = "Hello World";

The following example calculates the square root of the literal expression 3.1415 and assigns it to the variable x.

double x = Math.Sqrt( 3.1415 );

The following example prints the string but creates a new line before World is printed.

string s = "Hello \n World!";