2. WHAT IS DATA TYPE?
A Data type, in programming is a classification that specifies
which type of value a variable has and what type of
mathematical, relational or logical operations can be applied to it
without causing an error.
3. • INTEGER=It accepts only numbers.
• FLOAT=It takes only decimal numbers.
• CHAR=It accepts the single character only.
• STRING=It accepts numbers, characters, alphabets, special
characters, etc.
FOUR DATA TYPES IN C LANGUAGE
4. Basic Information Of Data Types
Data Type
Format
Specifier
Bytes
Integer %d 2
Float %f 4
Char %c 1
String %s 20
• Integers have 4 types
o Short signed int
o Short unsigned int
o Long signed int
o Long unsigned int
• Float has 3 types
o Float
o Double
o Long Double
• Char has 2 types
o Signed Char
o Unsigned Char
• String has 3 types
o String
o Wide String
o Wide Wide String
5. INTEGER DATA TYPE
• The int data type represents integer values, meaning any
positive or negative number, or zero, without a decimal point.
• An integer consists of an optional plus(+) or minus sign(-)
followed by a series of digits and cannot contain any other
character Commas, decimal points, or special characters such
as $ or e for exponential notation are not allowed
Data Type Range Bytes width Format Specifier
Short Signed int -32768 to +32767 2 %d
Short Unsigned int 0 to 65535 2 %u
Long Signed int -2147483648 to +2147483647 4 %ld
Long Unsigned int 0 to 4294967295 4 %lu
6. FLOAT DATA TYPE
• The float data type represents the floating point values, meaning any
signed or unsigned number having a decimal point.
• A float consists of an optional plus(+) or minus sign(-) followed by a series
of digits and must include a decimal point. It cannot contain any other
character Commas, decimal points, or special characters such as $ but
can include the letter e for exponential notation.
• Float is used to store decimal numbers with single precision.
• Double is used to store decimal numbers with double precision.
• Long Double is used to store decimal numbers with triple precision.
Data Type Range Bytes Width Format Specifier
Float 3.4e-38 to 3.4e+38 4 %f
Double 1.7e-308 to 1.7e+308 8 %lf
Long Double 3.4e-4932 to 1.1e+4932 10 %Lf
7. CHARACTER DATA TYPE
• A char represent individual characters. C also recognises
nonnumeric character data. Hence a char is any valid ASCII
character enclosed in single quotes.
• Char items can also be a single numeric digit such as 1,2,3…
But C makes a distinction between the character ‘1’ and the
number 1. As a character ’1’ it cannot be used in a
mathematical operation.
Data Type Range Bytes width Format Specifier
Signed Char -128 to -127 1 %c
Unsigned Char 0 to 255 1 %c
8. STRING DATA TYPE
• String data type is different from others, it accepts letters, numbers, words,
sentences, etc.
• Strings are actually one-dimensional array of characters terminated by
a null character '0'. Thus a null-terminated string contains the characters that
comprise the string followed by a null.
• The following declaration and initialization create a string consisting of the word
"Hello". To hold the null character at the end of the array, the size of the character
array containing the string is one more than the number of characters in the word
"Hello.“
char greeting[6] = {'H', 'e', 'l', 'l', 'o', '0'};
• If you follow the rule of array initialization then you can write the above statement as
follows:-
char greeting[]=“Hello”;