Hi Guest 1 HomePage 1 Jobs 1 WalkIn 1Articles  

 :) Latest Topic
Introduction to C
History of C Language
C Variables
Variables Types in C
C Identifiers
C Operators
C Comments
ASCII Value C
Constants C
Features of C
Install C Language
Start C Program
Compilation in c
printf() and scanf()
C Data Types
C Keyword
Format Specifier C
Format Specifier part2
Escape Sequence C
Tokens in C
Boolean in C
What are literals?
 


  

 
What are literals?
Question Posted on 26 Oct 2023

Home >> Tutorial >> C Language >> What are literals?


What are literals?
When we say about the Literals in C, these are constant values which are assigned to constant variables. We can also say that literals represent the fixed values which can not be modified. This will contains memory but not have references as variables. For understand we will take an example, const int=10; is a constant integer expression in which 10 is an integer literal.

Types of literals
There are four types of literals which exist in C programming:-

(1)Integer literal
(2)Float literal
(3)Character literal
(4)String literal


(1)Integer literal
It is a numeric literal which represents only the integer type values. This will not represent fractional or exponential part.

And this can be specified in three below ways:-

(i)Decimal Number (base 10)
This will be defined by representing the digits between 0 to 9. For example, 45, 67, etc.
(ii)Octal Number(base 8)
This will be defined as number in which 0 is followed by digits just like 0,1,2,3,4,5,6,7. And for example we have the values like 012,034,055 etc.
(iii)Hexadecimal Number(base 16)
This will be defined as a number in which 0x or 0X is mainly followed by the hexadecimal digits (0 to 9 , alphabetical charcter from (a-z) or (A-Z)).

An integer literal is mainly suffixed by below two sign qualifiers:-

L or l:-This is a size qualifier which specifies the size of the integer type as long.
L or l:-This is a sign qualifier which represent type of integer as unsigned. An unsigned qualifier contains only positive values.

Note:-The order of the qualifier is not considered, i.e., both lu and ul are the same.

Below is the example of integer literal.

bool value

Output of above code is given below:-

Integer literal Example : 19


(2)Float literal
This is a literal which contains only the floating-point values or we can say real numbers. And real number contain the number of parts just like fractional part, integer part, real part, exponential part. Here floating-point literal must be specified either in decimal or in exponential form. To explain you more lets go to the differnt things in brief:-

(i)Decimal form:-Here in C, decimal form must contain either deciaml point, exponential part or we can say both. And in absense of bothe of these value compiler will throw an error. And declmal notation can be prefixed either by "+" or "-" symbol which specifies the positive and negative numbers.
Example of Float literal in deciaml form are given below:-
2.4,+8.0,-3.7

Below is the example of float literal in decimal from

bool value

Output of above code :-
11.100000

(ii)Exponential Form:-We use exponential form to represent the number and this is bug magnitude. This will contains two parts:- Mantissa and Exponent. And for example number is 3120000000000, and it can be expressed as 3.12e12 in an exponential form.

Syntax of float literal in exponential form:-

[+/-] < Mantissa> [+/-] < Exponent>

and example of real literal in exponential notation are:-

+1e23, -9e2

Rules for creating a float literal in exponential notation:-

  • In exponential notation, the mantissa can be specified either in decimal or fractional form.

  • An exponent can be written in both uppercase and lowercase, i.e., e and E.

  • We can use both the signs, i.e., positive and negative, before the mantissa and exponent.

  • Spaces are not allowed



(3)Character literal
Character literal contains a single character enclosed in single quotes. And if we put multiple character, then we need to create an array. And if you try to input multiple charctare constant a warning is generated. Below is the example for this:-

bool value

As per the above example we use two characters "ak" within single quotes. So once we run this it will generate a warning as given below

bool value

Representation of character literal

Character literal can be present in below ways:-

  • It can be represented by specifying a single character within single quotes. For example, 'a', 'b', etc.

  • We can specify the escape sequence character within single quotes to represent a character literal. For example, '\n', '\a', '\b'.

  • We can also use the ASCII in integer to represent a character literal. For example, the ascii value of 65 is 'A'.

  • The octal and hexadecimal notation can be used as an escape sequence to represent a character literal. For example, '\023', '\0x12'.



(4)String literal
When we say about the string literal, this will represents multiple charcater which is enclosed in double-quotes. And this will contains an additional character '\0' only (null character), which gets automatically inserted. This null character specifies the termination of the string. We can use the '+' symbol to concatenate two strings.

String1="crackyour ";

String2="interview";

To concatenate the above two strings, we use '+' operator, as shown in the below statement:

"crackyour " + "interview"= crackyour interview





Other Important Questions
Features of C
Introduction to C
History of C Language
Install C Language
C Variables







 
Top Searches:asp net questions vb net questions sql query uddl questions class javascript Questions sharepoint interview questions and concept silverlight questions and concept wcf questions beans general knowledge ajax questions
PHP | Biztalk | Testing | SAP | HR |