Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +917541905230, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec

Tuesday, March 31, 2020

Literals in C

Literal: A literal represents a fixed value, The value that cannot be changed once defined is called literal or constant.

Literals in C | welcome2protec.com


A literal represents a fixed value, The value that cannot be changed once defined is called literal or constant. These constant values occupy memory but don't have any reference like variables. It can be of any type like int, char float, octal, hexadecimal etc.

There are five types of literals in C

  1. Integer literal
  2. Floating point or real literal
  3. Character literal
  4. String literal
  5. Boolean literal

Integer literal

Integer literal is followed by optional size or sign qualifier. L or l is a size qualifier. It specifies the size of an integer type as long. U or u is a sign qualifier. It specifies an integer type as unsigned (Can store only positive value).

An integer constant can specified by three ways:

  1. Decimal number: Any number that is from 0 to 9 is called decimal number and it's base is 10
  2. Octal number: prefixed with 0 followed by digits from 0 to 7. For example: 0126 is a octal number and it's base is 8.
  3. Hexadecimal number: number prefixed with 0x following digits from 0-9, a-z or A-Z. For example: 0x1A is a hexadecimal number and it's base is 16.

Following are the example of various types of integer literals:

  85         // Decimal                       
  0175;      // Octal
  0xa1b;     // Hexadecimal
  
  30	     // int
  30u        // unsigned int
  2016U		 // unsigned int
  25L		 // long
  30l        // long
  895UL		 // unsigned long
  30ul 	     // unsigned long

Note: Always be cautions while defining octal constants, Any numbers preceded with 0 must only contains digits from 0-7 otherwise compiler will report an error on compilation.

Order of the qualifier doesn't matter, ul or lu both are same.


Floating point or Real Literals:

You can represent floating point literals either in decimal form or exponential form.

Decimal form: While representing decimal form you must include the decimal point and it may preceded with + or - symbol representing positive or negative number.

For example: +12, -0.4, 5.6, 3.14159, .50

Exponential form: Exponential notations are helpful in representing any number with very big or small magnitude. It contains two parts, i.e. mantissa and exponent. For example: 96,000,000 and it can be expressed as 9.6e7 in exponential notation.

Syntax:

/* float literal in exponential notation */
 [+/-]<Mantissa> <e/E>[+/-]<Exponents>

For Example:

/* Example of float literal in exponential notation */
  4.6E-3, +1e23, 9.6e7, -9e2

More on this to be updated soon.....

--

--



Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +966532621401, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec

Help others by sharing this page.

Ahmad Irshad

Author & Editor

I love blogging, teaching, learning computer science and sharing it to others. I've written and develped this site so that students may learn computer science related tutorials eaisly. MCA / MCITP

0 Comments:

Post a Comment

Please don't enter any spam link in the comment box.


Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +966532621401, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec
Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec
Contact Us