Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Standard Data Types in C Language

 Integer Family
o char
o short
o int
o long
 Float Family
o float
o double

Bitsize of each data type is not common in all the C compilers (Native/ Cross)
 Native Compiler (s)
o Compiler designed for General Purpose OS like Windows or Linux
 Turbo C
 Borland C
 Cygwin
 TDM-GCC
 and more …..
 Cross Compiler (s)
o Compiler designed for a specific embedded platform using Microcontroller/ SoC
 Keil C51
 Keil ARMCC
 AVR GCC
 ARM CC
 IAR ARM
 and more …

Every compiler tool chain provides a portable integer data type specific header file stdint.h.
Portable integer data types across C Compilers (Native/ Cross):
 int8_t
o signed 8-bit data type
 uint8_t
o unsigned 8-bit data type
 int16_t
o signed 16-bit data type
 uint16_t
o unsigned 16-bit data type
 int32_t
o signed 32-bit data type
 uint32_t
o unsigned 32-bit data type
 int64_t
o signed 64-bit data type
 uint64_t
o unsigned 64-bit data type

In every C file in the project, we need to include stdint.h to make use of these portable types.
In real world applications, Integer Data can be
 Raw Data
o Needed during Core Platform Drivers
 binary
 Hexadecimal
o unsigned keyword to be specified along with data type
 unsigned keyword already added for portable data types
 Decimal Data
o signed/ unsigned keyword to be specified along with data type
 signed/ unsigned keyword already added for portable data types
o Signed
 Data can be negative, 0 and positive
o Unsigned
 Data can be 0 and positive
 String/ ASCII Data (128 in total)
o Alphanumeric and Special Character ASCII Data
 ‘A’ to ‘Z’
 ‘a’ to ‘z’
 ‘0’ to ‘9’
 Special Characters
 ‘+’
 ‘-‘
 ..and more
o Data Type preferred is char
o String is an array of characters

How to pick the right data type for a variable


 Based on the data range
o Min Value
o Max Value
 For raw data and decimal data, We use portable data types.
 For ASCII/string data, We use char data type

n-bit Min and Max value (n can be 8, 16, 32 and 64)


 Min value of an n-bit signed data: - 2 (n-1)
Eg: For 8-bit signed data, Min Value = -27 = -128

 Max value of an n-bit signed data: 2n-1 - 1


Eg: For 8-bit signed data, Max Value = 27 - 1 = 127

 Min value of an n-bit unsigned data: 0

 Max value of an n-bit unsigned data: 2 n - 1


Eg: For 8-bit unsigned data, Max Value = 2 8 - 1 = 255

You might also like