C Literals
Syntax
<data_type> <variable_name> = <value>;
Example
int num = 5;
float pi = 3.14;
char ch = 'A';
Output
The output of the above example will depend on the use case of the variables.
Explanation
In C programming language, literals are the constant values that can be assigned to variables. There are many types of literals in C, including integer literals, floating-point literals, character literals, and string literals.
Integer literals can be written in decimal, hexadecimal, or octal form. Floating-point literals can be written in decimal or exponential form. Single character literals are enclosed in single quotes, while string literals are enclosed in double quotes.
Use
Literals are used to initialize variables with constant values. They can also be used in expressions to perform arithmetic operations or comparisons.
Important Points
- Literals can be used to initialize variables with constant values.
- Integer literals can be written in decimal, hexadecimal, or octal form.
- Floating-point literals can be written in decimal or exponential form.
- Single character literals are enclosed in single quotes.
- String literals are enclosed in double quotes.
Summary
Literals are constant values that can be assigned to variables in C programming. There are various types of literals, including integers, floating-point numbers, characters, and strings. Using literals can be beneficial in writing efficient and readable code.