In the C programming language, a literal is a value that appears directly in the source code. There are several types of literals in C, including:
- Integer literals –
An integer literal is a whole number without a fractional component, such as 42 or -17.int a = 42; long b = -17; unsigned int c = 123456;
- Floating-point literals –
A floating-point literal is a number with a fractional component, such as 3.14 or -0.5.float d = 3.14; double e = -0.5; long double f = 0.000001;
- Character literals –
A character literal is a single character surrounded by single quotes, such as ‘A’ or ‘$’.char g = 'A'; char h = '$';
- String literals –
A string literal is a sequence of characters surrounded by double quotes, such as “hello” or “Good morning!”.char *i = "hello"; char *j = "Good morning!";
- Boolean literals –
A boolean literal is either the value true or false._Bool k = true; _Bool l = false;
Each type of literal has a specific type in C and must be used in the appropriate context. For example, an integer literal can be used as an argument to a function that takes an int, while a string literal can be used as an argument to a function that takes a char * or a string. Literals play an important role in C programming, as they provide a way to represent constant values in your code.
Please write comments below if you find anything incorrect, or you want to share more information about the topic discussed above. A gentle request to share this topic on your social media profile.