- USER CORNER
- OVERVIEW | BASICS
- C DATA TYPES
- VARIABLES IN C
- CONSTANTS or LITERALS
- C OPERATORS & ENUMS
- DECISION MAKING
- LOOPING IN C
- CONTROL FLOW IN C
- C FUNCTIONS
- ARRAYS IN C
- POINTERS IN C
Literals are a sequence of characters that represent constant values.
These constant values occupy memory but do not have any reference like variables.
Constants can be defined as any of the basic data types like an integer constant, a floating constant, a character constant, or a string literal. There are varius different constants as well.
There are basically four types of literals in C programming.
An Integer literals are the primary literals used in C programming.
During the declaration of an integer constant, a prefix is used along with the value to specify the base or radix.
An integer literal can also have a suffix that is a combination of U and L, for unsigned and long, respectively. It can be either uppercase or lowercase format and it also can be in any order.
Decimal(base 10) literals appear as ordinary numbers with no special notation.
An integer literal for the decimal number 12 is represented in C as 12 in decimal.
Hexadecimal numbers (base 16) appear with a leading 0x or 0X.
Octal (base 8) numbers appear with a leading in front of the digits.
an integer literal for the decimal number 12 is represented in C as 014 in octal.
/* decimal */014 /* octal */0x4c /* hexadecimal */45 /* int */20u /* unsigned int */20l /* long */20ul /* unsigned long */
Floating-point literals represent decimal numbers with fractional parts, such as 3.142. They can be expressed in either standard or scientific notaion, meaning that the number 563.84 also can be expressed as 5.6384e2.
3.14159 /* Legal */ 314159E-5L /* Legal */ 510E /* incomplete exponent */ 210f /* no decimal or exponent */ .e55 /* missing integer or fraction */
Character literals represent a single Unicode character and appear within a pair of single quotation marks.
'A' (or) '5' (or) 'p' etc.
String literals represent multiple characters and apear within a pair of double quotation marks. String literals are implemented in C by the using double quotes("").
"hello, world" "hello, \ world" "hello, " "wo" "rld"