C DATA TYPES AND CONSTANTS – A BRIEF DESCRIPTION

C DATATYPES AND CONSTANTS - A BRIEF DESCRIPTION

C CONSTANTS

As the name suggests, Constant is a value that we can’t change during execution of the program. Furthermore, we can define C Constant by the following definition..

A Constant is a fix value that the program can’t alter.. Constants can be of any fundamental data types. The way compiler represents each constant depends upon its type.

The another name for constant is LITERAL..

Generally, we can categorise Constants through the following..

Classification of C Constants - C DATATYPES
http://www.planetofcoders.com

The following image represents the categorisation of C Constants.

Primary Constants include the following constants,

  • INTEGER CONSTANT
  • REAL CONSTANT
  • CHARACTER CONSTANT

Furthermore, Secondary Constants include,

  • ARRAY
  • POINTER
  • STRUCTURE
  • UNION, etc. 

Generally, we will be focusing on each and every PRIMARY CONSTANT..

 

  • INTEGER CONSTANT

Integer constants are the primary Constants which are generally whole numbers having no decimal point. Furthermore, there are three types of integer constants on the basis of different number systems. The permissible characters which we can use in these constants are :

DECIMAL CONSTANTS – 0,1,2,3,4,5,6,7,8,9       ( Base 10 )

OCTAL CONSTANTS – 0,1,2,3,4,5,6,7       ( Base 8 )

HEXADECIMAL CONSTANTS – 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F       ( Base 16 )

Now, some examples of Valid Decimal Integer constants are..

  • 1
  • 15
  • 8907

Similarly, some examples of Invalid Decimal Integer constants are..

  • 1.9

Because ( . ) is an illegal character.

  • 50 3

Because there should be no blank space between the numbers.

  • 9#1

Because ( # ) is an illegal character.

  • 01

Because the first digit can never be zero.

  • 1,23

Because there should be no comma between the numbers.

 

Talking about Octal Integer constants, the First digit must be 0. For example,

  • 0
  • 05
  • 0235

 

Finally, in Hexadecimal Integer constants the first two characters should be 0x or 0X. Some examples are,

  • 0x12
  • 0XA34
  • 0xab

In Integer constants, the default type of the constant is int. Also, if the value of Integer constant exceeds, then the type is unsigned int or long int.

Leave a comment

Your email address will not be published. Required fields are marked *

8 thoughts on “C DATA TYPES AND CONSTANTS – A BRIEF DESCRIPTION”