A value made up of integers or digits is known as an integer variable. Even throughout the process of carrying out a code, such values remain constant. It does not reflect the value in proportional or exponential form. A numerical constant may have a positive or negative value. The variable must be contained by the defined data type’s scope. Inside a numerical constant, no blanks or asterisks are permitted. Open the shell-terminal in the Linux system using Ctrl+Alt+T. Now you have to make a new c type of file to write a C language code. So, use the “nano” command to create a file “test.c”.
After the opening of the nano file editor, type the below script of C language in it. This script is showing a single header library included in it. After that, the main function starts. The main method contains a constant type integer variable named “x” with integer value “54” in it. At the very next line, the print statement is printing out the constant value of variable “x”:
Save the file using the “Ctrl+S” command and quit. Now, it’s running for the compilation of the code. For this, perform the below query in the terminal:
It’s time to run the file using the “a.out” query. The output image is simply presenting the constant value “54” of integer type variable “x” using a print statement.
This is a kind of literal that just includes the floating-point value or true numbers. Such actual numbers have a variety of components, including numeric, real, and exponential bits. The numerical or exponential representation of the floating-point literal should be defined. They’re often referred to as true constants. A decimal point or an exponential may be found in a true constant. It could be either positive or negative. Inside a true constant, commas and blank space aren’t permitted. Let’s have a simple example of floating-point literal. Open the same file “test.c” to use it for floating-point literal discussion.
Now we have to update the code as shown in the image. One header and one main function are still there. In the main method, we have defined three float type variables “x”, “y”, and “z”. While two of them have been defined as literals using “const” at the start of them. Both of the float literals have floating-point values. The third float variable is not literal but simple. The third variable “z” has been using the sum of both the literal variables. A print statement has been used in the last line of code to output the sum of both the floating-point literals within the “z” variable. And the main method will be closed.
Compilation of the test.c file has been done using the stated-below “gcc” query in the console.
As the compilation of a file doesn’t show any error, this means the code is correct. Now run the file “test.c” using the “a.out” instruction below. The output shows a floating-point result as the sum of both literal variables “x” and “y”.
Just one single quote character is referred to as a character constant. It is 1 unit in size and could only hold one character. A letter might have been any alphabet (x, c, D, Z, etc.), any distinct character (&, $, #, @, etc.), or even a solitary digit (0–9). It could correspondingly be any escape series symbol, such as space “ ”, a blank or null character “o”, or even a new line “n”, and so on.
Let’s have a character literal example. So open the same file “test.c”.
Now type out the same code with a little update in it. Just change the “float” with the “char” keyword and specify a new variable “a” with a value “Aqsa”. This value is not a single character value, so the output must show some error upon compilation.
Compilation of the file “test.c” using the “gcc” compiler command shows an error of “multi-character constant.”
Now update the code again. This time, we have been using a single special character as the value of a character literal “c”. Save and quit the document.
Compile again via “gcc” as:
Now on running the code, you will get an output perfectly.
Double quotes have been used to wrap string literals. Simple words, escape series, and standard characters are among the characters in the string literal. String literals can be used to split an extensive string into several lines. Also, whitespace could be used to divide them. Here is a simple illustration of a string literal. Open the same file once again.
Now the same code has been updated with a string literal. This time we have used the “name” variable array as a string literal with a value “Aqsa”.
Compilation with a “gcc” command has proceeded correctly.
Upon execution, we can see the output of a string literal as below:
The concept of literals is relatively easy to understand and simple to implement on any Linux system. All the above queries work fine with all the distributions of Linux.