The document discusses data types in C programming. It describes the different types of data types as primary, derived, and user-defined. Primary data types include integer, floating point, character, and void types. Integer types can be signed or unsigned and include int, short int, long int, etc. Floating point types are float, double, and long double. Character types are char and unsigned char. Derived data types include arrays, pointers, and references. User-defined data types allow programmers to define their own data types using structures, unions, and enumerations. The document provides examples of declaring different primary data types with variable names.
1. DataTypes in ‘C’
By: Satveer Kaur, Assistant Professor, Khalsa College, Patiala 1
2. DataType
Is the description of nature of data.
Data can be in numeric form(integer
or real) or in character form(single
character or string).
By: Satveer Kaur, Assistant Professor, Khalsa College, Patiala 2
3. Types of Data
type
Primary(or fundamental)
data types
Derived data types
User-defined data types
By: Satveer Kaur, Assistant Professor, Khalsa College, Patiala 3
5. Integer types
signed
unsigned
• int
• short int
• long int
• unsigned int
• unsigned short
int
• unsigned long
int
By: Satveer Kaur, Assistant Professor, Khalsa College, Patiala 5
6. Integer types
• Size = 2 byte(16 bit)
• Range -32768 to 32767int or signed int
• Size = 1 byte (8 bit)
• Range -128 to 127
short int or
signed short int
• Size = 4 byte (32 bit)
• Range -2,147,483,648 to
2,147,483,647
long int or
signed long int
By: Satveer Kaur, Assistant Professor, Khalsa College, Patiala 6
7. Integer types
• Size = 2 byte (16 bit)
• Range 0 to 65535
unsigned
int
• Size = 1 byte (8 bit)
• Range = 0 to 255
unsigned
short int
• Size = 4 byte (32 bit)
• Range = 0 to 4,294,967,295
unsigned
long int
By: Satveer Kaur, Assistant Professor, Khalsa College, Patiala 7
8. Floating point
types
float
• Size = 4 byte (32 bit)
• Range 3.4E-38 to 3.4E+38
double
• Size = 8 byte (64 bit)
• Range is 1.7E-308 to 1.7E+308
long double
• Size = 10 byte (80 bit)
• Range 3.4E-4932 to 3.4E+4932
By: Satveer Kaur, Assistant Professor, Khalsa College, Patiala 8
9. Character
types
char or signed char
•Size = 1 byte (8 bit)
•Range -128 to 127
unsigned char
•Size = 1 byte (8 bit)
•Range 0 to 255
By: Satveer Kaur, Assistant Professor, Khalsa College, Patiala 9
10. Void types
void type has no values
Used to specify the type of functions
Also plays the role of generic type
By: Satveer Kaur, Assistant Professor, Khalsa College, Patiala 10
11. Data types and
their keywords
Data type Equivalent keyword
Character char
Unsigned character unsigned char
Signed character signed char
Signed integer signed int (or int)
Signed short integer signed short int (or short int or short)
Signed long integer signed long int (or long int or long)
Unsigned integer unsigned int (or unsigned)
Unsigned short integer unsigned short int (or unsigned short)
Unsigned long integer unsigned long int (or unsigned long)
Floating point float
Double-precision floating point double
Extended double precision floating
point
long double
By: Satveer Kaur, Assistant Professor, Khalsa College, Patiala 11
12. Derived data
types
Are derived from primary data types.
By: Satveer Kaur, Assistant Professor, Khalsa College, Patiala 12
• Sequence of data items having
homogenous values.
• Values are stored in adjacent locations.
Array
• Function pointers allow reference to the
functions with a particular signature.References
• Are used to access the memory locations
• And deal with the addresses of variables.Pointers
13. User-defined
data types
‘Type definition’ – a feature of ‘C’ allows the programmers to
define their own identifiers to represent an existing data.
By: Satveer Kaur, Assistant Professor, Khalsa College, Patiala 13
• a package of variables of different types under
a single name.
• To define a structure, ‘struct’ keyword is used.
Structure
• allow storage of various data types in the same
memory location.
• can defined with different members, but only a single
member can contain a value at a given time.
• To define a union, ‘union’ keyword is used.
Union
• a special data type that consists of integral
constants, and each of them is assigned with a
specific name.
• To define an enumeration, ‘enum’ keyword is
used.
Enumeration
15. Examples
#include <stdio.h>
int main()
{
int a = 400; // positive integer data type
float b = 5.2974; // float data type
char c = ‘A'; // char data type
long d = 42357; // long positive integer data type
long e = -41756; // long -ve integer data type
int f = -167; // -ve integer data type
short g = 330; // short +ve integer data type
short h = -830; // short -ve integer data type
double i = 7.1987654320; // double float data type
float j = -5.95; // float data type
}
By: Satveer Kaur, Assistant Professor, Khalsa College, Patiala 15