Lec 02 Part 2 Variables
Lec 02 Part 2 Variables
Autumn 2020
Data-types,
Variables and I/O
Integer Data Type
Integer data Bit
Minimum value Maximum value
type size
char 8 -27=-128 27-1=127
short int 16 -215=-32768 215-1=32767
int 32 -231=-2147483648 231-1=2147483647
long int 32 -231=-2147483648 231-1=2147483647
-263=- 263-
long long int 64
9223372036854775808 1=9223372036854775807
unsigned char 8 0 28-1=255
unsigned short int 16 0 216-1=65535
unsigned int 32 0 232-1=4294967295
unsigned long int 32 0 232-1=4294967295
264-
unsigned long long i
nt
64 0 1=1844674407370955161
5
Float Data Type
Like integers, C provides representations of
real numbers and those representations
are finite.
Depending on the size of the representation,
C's real numbers have got different names.
Real data type Bit size
float 32
double 64
long double 128
The sizeof function
#include <stdio.h>
void main()
{
printf(“size of short int: %d\n”,sizeof(short
int));
printf(“size of int is %d\n”,sizeof(int));
printf(“size of long int is %d\n”,sizeof(long
int));
}
Char data type
char for representing characters.
We need a way to express our thoughts in
writing.
This has been traditionally achieved by using
an alphabet of symbols with each symbol
representing a sound or a word or some
punctuation or special mark.
The computer also needs to communicate its
findings to the user in the form of
something written.
Char data type
Since the outputs are meant for human readers, it is
advisable that the computer somehow translates its
bit-wise world to a human-readable script.
The Roman script (mistakenly also called the English
script) is a natural candidate for the representation.
The Roman alphabet consists of the lower-case letters (a to
z), the upper case letters (A to Z), the numerals (0 through
9) and some punctuation symbols (period, comma, quotes
etc.).
In addition, computer developers planned for inclusion of
some more control symbols (hash, caret, underscore etc.).
Each such symbol is called a character.
ASCII Code
In order to promote interoperability between different computers,
some standard encoding scheme is adopted for the computer
character set.
This encoding is known as ASCII (abbreviation for American
Standard Code for Information Interchange).
In this scheme each character is assigned a unique integer value
between 32 and 127.
Since eight-bit units (bytes) are very common in a computer's
internal data representation, the code of a character is
represented by an 8-bit unit.
Since an 8-bit unit can hold a total of 28=256 values and the
computer character set is much smaller than that, some values of
this 8-bit unit do not correspond to visible characters.
Printable Characters
These values are often used for representing
invisible control characters (like line feed,
alarm, tab etc.) and extended Roman
letters (inflected letters like ä, é, ç).
Some values are reserved for possible future
use.
The ASCII encoding of the printable
characters is summarized in the following
table.
100000 - 32 in binary
0010 0000 = 20 in hexa-decimal