<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<style>
body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
}
.topnav {
  overflow: hidden;
  background-color: #f2f2f2;
}
.topnav a {
  float: left;
  color: #000080;
  text-align: center;
  padding: 14px 16px;
  text-decoration: none;
  font-size:20px;
}

.topnav a:hover {
  background-color: #ddd ;
  color: black;
}

.topnav a.active {
  background-color:#000080  ;
  color:white;
}
div.container {
    width: 100%;
    border: 1px solid gray;
}

header, footer {
    padding: 1em;
    color: white;
    background-color: #000080;
    clear: left;
    font-size:large;
    text-align: center;
}

nav {
    float: left;
    max-width: 180px;
    margin: 0;
    padding: 1em;
}

nav ul {
    list-style-type: none;
    padding: 0;
    font-size:20px;
}

nav ul a {
    text-decoration: none;
}

article {
    margin-left: 170px;
    border-left: 1px solid gray;
    padding: 1em;
    overflow: hidden;
} 
.icon-bar a {
    float: left;
    width: 5%;
    text-align: center;
    padding: 13px 0;
    color: #000080;
    font-size: 25px;
}
.vertical-menu {
    width: 180px;
}

.vertical-menu a {
    background-color:#eee;
    color:black;
    display: block;
    padding:15px;
    text-decoration: none;
}

.vertical-menu a:hover {
    background-color: #ccc;
}

.vertical-menu a.active {
    background-color: #000080;
    color: white;
}
a{
    text-decoration: none;
    display: inline-block;
    padding: 9px 17px;
}

a:hover {
    background-color: #ddd;
    color: black;
}

.previous {
    background-color:#000080;
    color: white;
}

.next {
    background-color: #000080;
    color: white;
	margin-left:780px;
}

</style>

</head>
<body>
<header>
<h1>C Programming</h1>
</header>

<div class="topnav">
  <div class="icon-bar"> <a class="" href="index.html"><i class="fa fa-home"></i></a> </div>
<a href="allprolang.html">All Languages</a>
  <a class="active" href="c_overview.html">C</a>
  <a href="cpp_overview.html">CPP</a>
  <a href="java_overview.html">JAVA</a>
  <a href="html_overview.html">HTML</a>
  <a href="css_overview.html">CSS</a>
  <a href="javascript_overview.html">JAVASCRIPT</a>
  <a href="python_overview.html">PYTHON</a>
  <div class="icon-bar"> <a class="" href="#"><i class="fa fa-search"></i></a> </div></div>
<nav>
<div class="vertical-menu">
   <a href="c_overview.html">Overview</a>
   <a href="c_prostuct.html">Program Structures</a>
   <a href="c_basicsyntax.html">Basic Syntax</a>
   <a href="c_datatypes.html">DataTypes</a>
   <a href="c_variables.html">Variables</a>
   <a class="active" href="c_constliterals.html">Constants&Literals </a>
   <a href="c_operators.html">Operators</a>
   <a href="c_desisonmake.html">Decision Making</a>
   <a href="c_loops.html">Loops</a>
   <a href="c_functions.html">Functions</a>
   <a href="c_scope.html">Scope Rules</a>
   <a href="c_arrays.html">Arrays</a>
   <a href="c_pointers.html">Pointers</a>
   <a href="c_strings.html">Strings</a>
   <a href="c_structunion.html">Structures&Unions </a>
   <a href="c_ipop.html">Input&Output </a>
   <a href="c_fileio.html">File I/O </a>
 </div> </nav>
<article>
<a href="c_variables.html" class="previous">&laquo; Previous</a>
<a href="c_operators.html" class="next">Next &raquo;</a>

<h1 style="color:#000080";> Constants & Literals In C</h1>
<p>Constants refer to fixed values that the program may not alter during its
execution. These fixed values are also called literals.</p>
<p>Constants can be of any of the basic data types like an integer constant, a
floating constant, a character constant, or a string literal. There are enumeration
constants as well.</p>
<p>Constants are treated just like regular variables except that their values cannot
be modified after their definition.</p>
<p><h2>Integer Literals</h2></p>
<p>An integer literal can be a decimal, octal, or hexadecimal constant. A prefix
specifies the base or radix: 0x or 0X for hexadecimal, 0 for octal, and nothing for
decimal.</p>
An integer literal can also have a suffix that is a combination of U and L, for
unsigned and long, respectively. The suffix can be uppercase or lowercase and
can be in any order.</p>
<p>Here are some examples of integer literals:<br></p>
<img src="images/c_literal1.png"/>
<p><h2>Floating-point Literals</h2></p>
<p>A floating-point literal has an integer part, a decimal point, a fractional part, and
an exponent part. You can represent floating point literals either in decimal form
or exponential form.</p>
<p>While representing decimal form, you must include the decimal point, the
exponent, or both; and while representing exponential form, you must include
the integer part, the fractional part, or both. The signed exponent is introduced
by e or E.</p>																						
<p>Here are some examples of floating-point literals:</p>
<img src="images/c_literal2.png"/>
<p><h2>Character Constants</h2></p>
<p>Character literals are enclosed in single quotes, e.g., 'x' can be stored in a
simple variable of char type.</p>
<p>A character literal can be a plain character (e.g., 'x'), an escape sequence (e.g.,
'\t'), or a universal character (e.g., '\u02C0').</p>
<p>There are certain characters in C that represent special meaning when preceded
by a backslash, for example, newline (\n) or tab (\t). Here, you have a list of
such escape sequence codes:</p>
<img src="images/c_literal3.png">
<img src="images/c_literal4.png">
<p>Following is the example to show a few escape sequence characters:</p>
<img src="images/c_literal5.png">
<p>When the above code is compiled and executed, it produces the following result:</p>
<p><h3>Hello World</h3></p>
<p><h2>String Literals</h2></p>
<p>A "string literal" is a sequence of characters from the source character set enclosed in double quotation marks (" "). String literals are used to represent a sequence of characters which, taken together, form a null-terminated string. You must always prefix wide-string literals with the letter L.</p>
<img src="images/c_literal6.png">
<p><h2>Defining Constants</h2></p>
<p>There are two simple ways in C to define constants:</p>
<p>* Using #define preprocessor</p>
<p>* Using const keyword</p>
<p><h3>The #define Preprocessor</h3></p>
Given below is the form to use #define preprocessor to define a constant:</p>
<p>#define identifier value</p>
</p>The following example explains it in detail:</p>
<img src="images/c_literal7.png">
<img src="images/c_literal8.png">
<p>When the above code is compiled and executed, it produces the following result:</p>
<p><h3>value of area : 50</h3></p>
<p><h2>The const Keyword</h2></p>
<p>You can use const prefix to declare constants with a specific type as follows:</p>
<p>const type variable = value;<p>
<p>The following example explains it in detail:</p>
<img src="images/c_literal9.png">
<p>When the above code is compiled and executed, it produces the following result:</p>
<p><h3>value of area : 5</h3></p>
<p>Note that it is a good programming practice to define constants in CAPITALS.</p>
<a href="c_variables.html" class="previous">&laquo; Previous</a>
<a href="c_operators.html" class="next">Next &raquo;</a>

</article>
<footer>Devoloped by LE's</footer>
</body>
</html>