Data Types
Data Types
Data Types
1
Content
• Introduction
• Types
• Void
• Character
• Integer
• Float
• Double
• Short
• Long
• Signed and Unsigned
• Derived
• User Defined
• Enumerate
Programming in C
Introduction
• The type of valued used.
• Instruction to compiler.
• Need to allocate memory.
• Associated with format specifier.
• Format specifiers are needed to read and write value of particular type.
• Format specifiers are preceded with percentage (%)
Programming in C
Types
Programming in C
Void Type
• Void means nothing.
• Used when identifier is not belong to any type.
• Used in function return type.
• Keyword is ‘void’
Programming in C
Character Type
• Handle single character value. Character char %c
Programming in C
Integer Type
• Numerical Data type. Integer int %d
Programming in C
Float Type
• Numerical decimal values. Float float %f
Programming in C
Double Type
• Numeric real numbers. Double double %lf
Programming in C
Short type
• Used to store shorter range of value. Data Type Keyword Format
Specifier
• Combined with Integer data type. Short Integer short int %hd
10
Programming in C
Long type
• Increase the size of type.
Data Type Keyword Format
• Long is combined with Integer Specifier
and Double Type. Long Integer long int %ld
• Long Integer allocated 4 byte Long Long Integer long long int %lld
as like default integer. Long Double long double %Ld
Programming in C
Signed or Unsigned Type
• Both negative and positive values are allowed Data Type Keyword Format
by default. Specifier
• Default sing is positive if no sign is specified Unsigned Short unsigned short int %hu
in value.
Integer
• Negative Sign should be given explicitly. Unsigned Integer unsigned int %u
• The keyword is ‘signed’ to have both positive Unsigned Long unsigned long int %lu
and negative value.
Integer
• Unsigned is used to restrict only with positive
values.
• The keyword is ‘unsigned’
• Combined with Character, Integer and Short
type 12
Programming in C
Derived Data type
• Derived from basic data type.
• Group more than one value in single identifier.
• Array
• Pointer
13
Programming in C
User Defined Data Type
• New data type
• Formed by grouping basic data type.
• Enumerate
• Union
• Structure
14
Programming in C
Enumerate Data Type
• User defined data type.
• Groups more than one constants.
• Assign name to integral constant.
• Default value of first integral constant is 0.
• Make easy to refer the value.
• The keyword used is ‘enum’
• Syntax
• enum Enumerate_Name{Const1, Const2…};
• enum Enumerat_Name{Const1=10, Const2…};
15
Programming in C