Position: Index > Data Circuit >

Data Types and Constants in C-Chapter 1

2016-10-13 15:34  
Declaration:We aim to transmit more information by carrying articles . We will delete it soon, if we are involved in the problems of article content ,copyright or other problems.

To use any language in communication (to write/to speak), we need to understand it’s grammar first.  In the case of a programming language likeC, the scenario is same as in the case of a communication language. We need to understand the grammar of C programming language first. So here begins:-

In this article we explainData TypesandConstants

The basic grammar of C can be explained through:-

Data TypesConstantsVariables and KeywordsOperators and OperandsControl structures (branching and looping)FunctionsArraysStringsPointersStructuresFiles

Data Types

There are 4 data types in C language. They are:-

int– This data type is used to define an integer number (-….-3,-2,-1,0,1,2,3….). A single integer occupies 2 bytes.char– Used to define characters. A single character occupy 1 byte.float– Used to definefloating point numbers(single precision). Occupies 4 bytes.double– Used for double precision floating point numbers(double precision). Occupies 8 bytes.

Note:-Single precision and Double precision basically differs in the number of digits represented after the decimal point. Double precision number will represent more digits after the decimal point than a single precision number.Example:-Single precision – 32.75   and double precision -  32.7543

Data Types can also be classified as shown in the image below – Primitive, Derived and User Defined.

C Data Types- C programming tutorial

Image Courtesy

Primitive data typesare the first form – the basic data types (int,char,float,double).Derived data typesare a derivative of primitive data types known as arrays, pointer and function.User defineddata types are those data types which are defined by the user/programmer himself.

Note:We will learn about Derived and user defined data types in coming chapters.

Data Type Qualifiers

Each of these data type has got qualifiers. The purpose of a qualifier is to manipulate the range of a particular data type or its size. The 4 qualifiers in C arelong,short,signed and unsigned.First two long and short are calledsize qualifiersand the other two signed and unsigned are calledsign qualifiers.

Example: int– when declared normally is of 2 bytes. If it is declared asunsigned int– then its range is from 0 to 65535. In other case, if it is declared assigned int– then its range is from (-32767 to 32768). In the case of signed int, one bit (MSB) is used to store the sign of the integer /-. This basically means the programmer will not be able to display/store a number higher than 65535 using unsigned int. Similarly it is not possible to manipulate a number beyond -32767 or 327678 using signed int.

The qualifiers long and short are used to increase storage size of the data type.

Example:Integer data type int is normally 2 byte. If you declare it aslong int– then its size will increase from2 bytes to 4 bytes. Similarly if you declare it asshort int– its size will reduce from2 bytes to 1 byte. 

The table below describes all data types and the most commonly used qualifier combinations – with its size,range and format specifier.Note:You will learn more about the use of format specifiers in coming chapters.


Format Specifier


Date Range



1 byte

-128 to 127



2 bytes

0 to 255



4 bytes

-3.4e38to 3.4e38



8 bytes

-1.7e38to 1.7e38

long int


4 bytes

-231to 231

unsigned int


2 bytes

0 to 65535

long double


16 bytes

-3.4e38to 3.4e38

Unsigned char


1 byte

0 to 255


There are 4 types of constants in C.

Integer constantsCharacter constantsReal/Floating point constantsString constants

C programming tutorialImage Courtesy

By definition, a constant is a quantity that does not change throughout the execution of a program.

Integer Constants

An integer constant is an integer quantity which contains a sequence of digits.It should not have a decimal point. Blanks and commas are not allowed within an integer constant.An integer constant can be either ve or -ve. The constant must lie within the range of the declared data type (including qualifiers long,short etc.).

Exampleof valid integer constants:-976    8987   5   -25  etc.

Example of invalidinteger constants:- 78.43   7-8   89,76  etc.

An integer constant can be eitherDecimal, Hexa Decimal or Octal. See the table below to understand how these 3 different constants are defined in C.

Integer Type




Hexa Decimal




Long Hexa Decimal


I or L

Unsigned Long Hexa Decimal


UI or UL

Long Octal


I or L

A decimal constant can contain any combination of integers from 0 through 9. Ex: 189      0      75       87A hexa decimal constant should begin with 0X or 0x. Ex: 0x65F  or 0X7AAn octal constant should begin with digit 0. It can take any digits from 0 through 7.

Note:-There is no binary integer constant in C by default. This means, you cant give a binary number directly to program by writing sth like:-0b11001011– which is meaningless and result in an error. How ever, programmer can add a preprocessor (which we will learn later) to accept binary numbers in a program.

Floating Point Constants

They are also known as real constants. A real constant contains a decimal point or an exponent. It can be either ve or -ve. Commas and blank space are not allowed within a real constant.

Examples:- 254.175,      -16.47      -0.5e-7     4.1e8

Character Constant

A character constant is a character which is enclosed in single quotes. A character constant is of size 1byte and can contain only 1 character. A character can be an alphabet like a,b,A,C etc or a special character like &,^, $, #,@ etc or a single digit from 0 through 9. It can also be an escape sequence character like space ‘ ‘ or a null character ‘\o’  or  a new line ‘\n’  etc.

Example: ‘A’       ‘a’     ‘ b’      ’8′     ‘#’  etc.

Each character has a corresponding ASCII value.ASCII valueis the numeric code of a particular character and is stored inside the machine’s character set. 

Note:-It is good that you read more about ASCII. There are basically two types of ASCII characters known ascontrol charactersandprintable characters.Control characters are usually used to control a device using the program or to manipulate some logic inside a program. Control characters are not usually printed to an output device. Printable characters are usually printed to a display device or a printer.

String Constants

      A string constant is a collection of characters enclosed in double quotations “”It may contain alphabets, digits, special characters and blank space.

      Example:   “Circuits Today123″

      Reprinted Url Of This Article: