c programming data types

A data type is essential to identify the storage representation and the type of operations that can be performed on that data. In general, data type associated with variable indicates,

‘C’ supports four basic data type which can be grouped under two groups of data types.

  1. integral data type
  2. Floating point data type

Integral Data Type

An integral Data type is used to store whole numbers and characters. It can be further classification as,

Integer data type

Signed integer: signed integers are those integers which use 15 bits for storing the magnitude of a number and 1 bit to store its sign. The left-most bit i.e., a 16th bit used the sign, it is 1 for negative number and ‘0’ for the positive number.

Unsigned integer: unsigned integer use all 16 bit i.e., (15+1) bits to store the magnitude i.e., these are the whole numbers that always hold positive values and the sign bit also contains the value.

Character Data Type
Type Size Range Format Specifier
char (or) signed char 1 -128 to +127 %c
unsigned char 1 0 to 255 %c

Floating-point Datatype

Data Type qualifiers

    1. short
    2. long
    3. signed
    4. unsigned

Constants 

A quantity or number that does not vary during the execution of the program is known as constants. These constants are classified into two types

  1. Numeric constants
  2. Character constants
Numeric constants

Numeric constants can be classified as, integer constants and real constants

Integer constants The integer constants are confined to the following features.

Blank spaces and commas are not allowed within the integer constant. An integer constant can be either positive or negative value.
Ex: 400, +789, -100, etc.

The range of integer constants depending on the machine. ‘C’ provides a range of -32768 to 32767 integer constants for 16-bit word length machine and -1247483648 to 2147483647 for 32 bit.

A long integer unsigned integer and unsigned long integer constant can be represented by appending the l or L, u or U or UL respectively.
Ex: long integer constants: 98491560l, 98491560L

unsigned integer constants 55596U, 55596u

unsigned long integer constants 955713345I, 955713345L

An integer constant can be represented in any one of the three numbers system i.e. decimal, octal, hexadecimal.
Decimal integers these constant consists of numbers from 0 to 9 preceded by an optional sign.Ex: +129, -95,145

An octal integer these constant consists of any digits from 0 to 7 with leading zero (‘0’).
Ex: 037, 067,050

Hexa-decimal these integer constants consist of a combination of digits from 0 to 9 and alphabets, i.e.a-f or A-F. The alphabets a to f represent numbers 10 to 15 respectively. Hexadecimal numbers are preceded by 0x or 0X.
Ex: 0xA5, 0XA5, 0xa6c

Real Constants

Real constants are the quantities which contain fractional part i.e., decimal point. Real Constants are also known as the floating-point constant. Real constants can be represented in two ways.

Decimal form

Exponential form

The exponential form is used to represent the real constants both either too large or too small value.
Ex: 8500000000 can be represented as 8.5e9. 0.000000786 can be represented as 7.86e-7.

Character Constants

The character constants can be divided into two types,

Character constants A single character constant is a single digit, alphabet or special symbol, enclosed within single quotes.
Ex: 'a', '1', '+'

String constants A string constant contains a group of character (i.e., alphabets, digits, special symbols, and blank spaces)
Ex: "welcome", "+,-" "10+2".

Type conversion

Ex:

printf (“\ntwo integers (5&2) : %d”, 5/2);   2
printf (“\none int and one float (5.5&2) : %f”, 5.5/2);     2.75
printf (“\ntwo integers (5&2) : %f”,(float) 5/2);      2.5