SlideShare une entreprise Scribd logo
1  sur  27
Télécharger pour lire hors ligne
ASSIGNMENT-II
DATA TYPES
SUBMITTED TO-
Mr. Vikas Somani
SUBMITTED BY-
Harshita Yadav
Bhavyata Sukhwal
What Is Data Type?
• A Data type is a Type of Data.
• Data type is a data storage format that can
contain a specific type or range of values.
• Data types in C refers to an extensive system
used for declaring variable for function of
different types. The type of a variable determines
how much space it occupies in storage and how
the bit pattern stored in interpreted.
A Data Type Is Used to-
• Identify the type of a variable when the
variable is declared.
• Identify the type of the return value of a
function.
• Identify the type of a Parameter expected by
a function.
Classification of Data types
S.N. TYPES & DESCRIPTIONS
1.
Basic Types
They are arithmetic types and are further classified into: (a) integer types
(b) character types and (c) floating-point types.
2.
Enumerated types
They are again arithmetic types and they are used to define variables that
can only assign a certain discrete integer value throughout the program.
3.
The type void
The type specifier void indicates that no value is available.
4.
Derived types
They include (a) pointer types (b) Array types (c) structure types (d) union
types and (e) function types
Basic types
Integer types
• Integers are whole numbers with the wide range of
values that are machine dependent.
• Keyword int is used for declaring the variable with
integer type. For example--
int var1;
• Integer occupies 2 bytes memory space and its value
range limited to -32768 to 32767
• Range of integer is 2^-15 to 2^+15
• Each type is again classified into signed and
unsigned integer.
•The following table provides the details of standard
integer types with their storage sizes and value ranges-
Type Storage size Value range
Int 2 bytes -32,768 to 32,767
unsigned
int
2 bytes 0 to 65,535
short 2 bytes -32,768 to 32,767
Unsigned
Short
2 bytes -0 to 65,535
Long 4 bytes -2,147,483,648 to 2,147,483,647
Unsigned
long
4 bytes 0 to 4,294,967,295
Character types
• All single character used in programs belong to
character type.
• The range of values that can be stored in a
variable of character data type is -128 to 127.
• The char data type holds exactly 8bits (1 byte).
• Keyword char is used for declaring the variable
with character type. For example--
char var1=h;
Here, var4 is a variable of type character
which is storing a character ‘h’.
Unsigned Char- The unsigned char is a variation of char
type. The size of a variable of unsigned char is also 1 byte.
As the name itself indicates, the range of values that can
be stored in a variable of type unsigned char is “0 to 255”.
CONTINUED…
Floating-Point Type
• All numeric data type items with fractional part
belong to float type.
• The keyword float is used to declare variables of
float type.
float var1;
• A variable of float type requires 4 bytes and the
range of values that can be stored in it, is 3.4e-
38 to 3.4e+38
•The following table provide the details of standard
floating-point types with storage sizes and value ranges
and their precision-
TYPE STORAGE SIZE VALUE RANGE PRECISION
Float 4 byte 1.2E-38 to 3.4E+38 6 decimal places
Double 8 byte
2.3E-308 to 1.7E+308 15 decimal
places
Long double 10 byte 3.4E-4932 to 1.1E+4932
19 decimal
places
Enumerated types
• Enumerated types allow us to create our own symbolic names
for a list of related ideas.
• The keyword for enumerated type is enum.
• Enumerated types are used to make a program clearer to
the reader/maintainer of the program.
For example, say we want to write a program that check for
keyboard presses to find if the down arrow or up arrow has
been pressed. We could say: if (press_value==32). 32 is the
computers representation of the down arrow. Or, we could
create our own enumerated type with the key words: down-
arrow and up_arrow. Then we could say: if
(press_value==down_arrow). This second version is much
more readable and understandable to the programmer.
CONTINUED…
The Type Void
• The void type specifies that no value is available. It is
used in two kinds of situations-
S.N. TYPES & DESCRIPTION
1. Function returns as void
There are various functions in C which do not return any value or
you can say they return void. A function with no return value has the
return type as void.
2. Function arguments as void
There are various functions in C which do not accept any parameter.
A function with no parameter can accept a void.
Derived Types
POINTER TYPES
• A pointer is a variable whose value is the address
of another value. i.e. direct address of the
memory location.
• The general form of a pointer variable
declaration is-
datatype *var-name;
• The asterisk * used for multiplication. However,
in this statement the asterisk is being used to
designate a variable as a pointer.
CONTINUED…
• Lets try to understand the concept-
• As shown in the above diagram:
• A normal variable ‘var’ has a memory address of 1001 and holds a value of 50.
• A pointer variable has its own address 2047 but stores 1001, which is the address
of the variable ‘var’.
1001
1001 2047
var
(normal variable)
Ptr
(pointer)
How to declare a pointer?
• A pointer is declared as-
<pointer type> *<pointer-name>
In the above declaration:
1. pointer-type : It specifies the type of pointer. It can be
int, char, float etc. this type specifies the type of variable
whose address this pointer can store.
2. pointer-name : It can be any name specified by the user.
Professionally, there are some coding styles which every code
follows. The pointer names commonly start with ‘P’ or end
with ‘ptr’.
Example :
char *chptr;
ARRAY TYPES
• Array is a kind of data structure that can store a fixed-
size sequential collection of elements of the same type.
• An array is used to store a collection of data, but it is
often more useful to think of an array as a collection of
variables of the same type.
• All arrays consists of contiguous memory locations.
The lowest address corresponds to the first element
and the highest address to the last element.
Numbers[0] Numbers[1] Numbers[2] Numbers[3] …..
First Element Last Element
How to declare Array?
• To declare an array, a programmer specifies the type
of the elements and the number of elements required
by an array as follows-
type arrayName[arraySize];
This is called a single dimensional array. The
arraySize must be an integer constant greater than
zero and type can be any valid C data type. For
example, to declare a 10-element array called balance
of type double, use this statement –
double balance[10];
Here balance is a variable array which is sufficient to hold up to 10
doubles numbers.
STRUCTURE TYPES
• Structure is a user defined data the type available in C
that allows to combine data items of different kinds.
• Structures are used to represent a record.
• To define a structure, you must use struct statement.
The struct statement defines a new data type, with
more than one member.
CONTINUED…
• The format of the struct statement is as follows-
struct [structure tag]
{
member defination;
member defination;
….
member defination;
}
[one or more structure
variables];
UNION TYPES
• A union is a special data type available in C that
allows to store different data types in the same
memory location.
• Unions provide an efficient way of using the same
memory location for multi-purpose.
• To define a union, you must use a union statement.
• The union statement defines a new data type with
more than one member for your program.
CONTINUED…
• The format of the union statement is as follows-
union [union tag]
{
member defination;
member defination;
….
member defination;
}
FUNCTION TYPES
• A function type describes a function that returns a value of a
specified type.
• If the function returns no value, it should be declared as
“function returning void” as follows:
void function1();
• In the following example, the data type for the function is
“function returning int”:
int uppercase(int lc)
{
int uc=lc+0x20;
return uc;
}
cassignmentii-170424105623.pdf

Contenu connexe

Similaire à cassignmentii-170424105623.pdf

variablesfinal-170820055428 data type results
variablesfinal-170820055428 data type resultsvariablesfinal-170820055428 data type results
variablesfinal-170820055428 data type results
atifmugheesv
 
C the basic concepts
C the basic conceptsC the basic concepts
C the basic concepts
Abhinav Vatsa
 

Similaire à cassignmentii-170424105623.pdf (20)

Datatypes
DatatypesDatatypes
Datatypes
 
Variables in C++, data types in c++
Variables in C++, data types in c++Variables in C++, data types in c++
Variables in C++, data types in c++
 
variablesfinal-170820055428 data type results
variablesfinal-170820055428 data type resultsvariablesfinal-170820055428 data type results
variablesfinal-170820055428 data type results
 
CS4443 - Modern Programming Language - I Lecture (2)
CS4443 - Modern Programming Language - I  Lecture (2)CS4443 - Modern Programming Language - I  Lecture (2)
CS4443 - Modern Programming Language - I Lecture (2)
 
Module 1:Introduction
Module 1:IntroductionModule 1:Introduction
Module 1:Introduction
 
Data Types in C language
Data Types in C languageData Types in C language
Data Types in C language
 
Data types in C
Data types in CData types in C
Data types in C
 
C96e1 session3 c++
C96e1 session3 c++C96e1 session3 c++
C96e1 session3 c++
 
Chap 2(const var-datatype)
Chap 2(const var-datatype)Chap 2(const var-datatype)
Chap 2(const var-datatype)
 
C the basic concepts
C the basic conceptsC the basic concepts
C the basic concepts
 
Datatypes in c
Datatypes in cDatatypes in c
Datatypes in c
 
Constant, variables, data types
Constant, variables, data typesConstant, variables, data types
Constant, variables, data types
 
C presentation! BATRA COMPUTER CENTRE
C presentation! BATRA  COMPUTER  CENTRE C presentation! BATRA  COMPUTER  CENTRE
C presentation! BATRA COMPUTER CENTRE
 
Lecture 2
Lecture 2Lecture 2
Lecture 2
 
5-Lec - Datatypes.ppt
5-Lec - Datatypes.ppt5-Lec - Datatypes.ppt
5-Lec - Datatypes.ppt
 
Csc240 -lecture_4
Csc240  -lecture_4Csc240  -lecture_4
Csc240 -lecture_4
 
C language
C languageC language
C language
 
C#
C#C#
C#
 
LEARN C# PROGRAMMING WITH GMT
LEARN C# PROGRAMMING WITH GMTLEARN C# PROGRAMMING WITH GMT
LEARN C# PROGRAMMING WITH GMT
 
datatypes-200723165518 (1).pptx
datatypes-200723165518 (1).pptxdatatypes-200723165518 (1).pptx
datatypes-200723165518 (1).pptx
 

Dernier

Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Christo Ananth
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Dr.Costas Sachpazis
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
dharasingh5698
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
Tonystark477637
 

Dernier (20)

Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort ServiceCall Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
Call Girls in Ramesh Nagar Delhi 💯 Call Us 🔝9953056974 🔝 Escort Service
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSUNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 

cassignmentii-170424105623.pdf

  • 1. ASSIGNMENT-II DATA TYPES SUBMITTED TO- Mr. Vikas Somani SUBMITTED BY- Harshita Yadav Bhavyata Sukhwal
  • 2. What Is Data Type? • A Data type is a Type of Data. • Data type is a data storage format that can contain a specific type or range of values. • Data types in C refers to an extensive system used for declaring variable for function of different types. The type of a variable determines how much space it occupies in storage and how the bit pattern stored in interpreted.
  • 3. A Data Type Is Used to- • Identify the type of a variable when the variable is declared. • Identify the type of the return value of a function. • Identify the type of a Parameter expected by a function.
  • 4. Classification of Data types S.N. TYPES & DESCRIPTIONS 1. Basic Types They are arithmetic types and are further classified into: (a) integer types (b) character types and (c) floating-point types. 2. Enumerated types They are again arithmetic types and they are used to define variables that can only assign a certain discrete integer value throughout the program. 3. The type void The type specifier void indicates that no value is available. 4. Derived types They include (a) pointer types (b) Array types (c) structure types (d) union types and (e) function types
  • 6. Integer types • Integers are whole numbers with the wide range of values that are machine dependent. • Keyword int is used for declaring the variable with integer type. For example-- int var1; • Integer occupies 2 bytes memory space and its value range limited to -32768 to 32767 • Range of integer is 2^-15 to 2^+15 • Each type is again classified into signed and unsigned integer.
  • 7. •The following table provides the details of standard integer types with their storage sizes and value ranges- Type Storage size Value range Int 2 bytes -32,768 to 32,767 unsigned int 2 bytes 0 to 65,535 short 2 bytes -32,768 to 32,767 Unsigned Short 2 bytes -0 to 65,535 Long 4 bytes -2,147,483,648 to 2,147,483,647 Unsigned long 4 bytes 0 to 4,294,967,295
  • 8. Character types • All single character used in programs belong to character type. • The range of values that can be stored in a variable of character data type is -128 to 127. • The char data type holds exactly 8bits (1 byte). • Keyword char is used for declaring the variable with character type. For example-- char var1=h; Here, var4 is a variable of type character which is storing a character ‘h’.
  • 9. Unsigned Char- The unsigned char is a variation of char type. The size of a variable of unsigned char is also 1 byte. As the name itself indicates, the range of values that can be stored in a variable of type unsigned char is “0 to 255”. CONTINUED…
  • 10. Floating-Point Type • All numeric data type items with fractional part belong to float type. • The keyword float is used to declare variables of float type. float var1; • A variable of float type requires 4 bytes and the range of values that can be stored in it, is 3.4e- 38 to 3.4e+38
  • 11. •The following table provide the details of standard floating-point types with storage sizes and value ranges and their precision- TYPE STORAGE SIZE VALUE RANGE PRECISION Float 4 byte 1.2E-38 to 3.4E+38 6 decimal places Double 8 byte 2.3E-308 to 1.7E+308 15 decimal places Long double 10 byte 3.4E-4932 to 1.1E+4932 19 decimal places
  • 13. • Enumerated types allow us to create our own symbolic names for a list of related ideas. • The keyword for enumerated type is enum. • Enumerated types are used to make a program clearer to the reader/maintainer of the program. For example, say we want to write a program that check for keyboard presses to find if the down arrow or up arrow has been pressed. We could say: if (press_value==32). 32 is the computers representation of the down arrow. Or, we could create our own enumerated type with the key words: down- arrow and up_arrow. Then we could say: if (press_value==down_arrow). This second version is much more readable and understandable to the programmer. CONTINUED…
  • 15. • The void type specifies that no value is available. It is used in two kinds of situations- S.N. TYPES & DESCRIPTION 1. Function returns as void There are various functions in C which do not return any value or you can say they return void. A function with no return value has the return type as void. 2. Function arguments as void There are various functions in C which do not accept any parameter. A function with no parameter can accept a void.
  • 17. POINTER TYPES • A pointer is a variable whose value is the address of another value. i.e. direct address of the memory location. • The general form of a pointer variable declaration is- datatype *var-name; • The asterisk * used for multiplication. However, in this statement the asterisk is being used to designate a variable as a pointer.
  • 18. CONTINUED… • Lets try to understand the concept- • As shown in the above diagram: • A normal variable ‘var’ has a memory address of 1001 and holds a value of 50. • A pointer variable has its own address 2047 but stores 1001, which is the address of the variable ‘var’. 1001 1001 2047 var (normal variable) Ptr (pointer)
  • 19. How to declare a pointer? • A pointer is declared as- <pointer type> *<pointer-name> In the above declaration: 1. pointer-type : It specifies the type of pointer. It can be int, char, float etc. this type specifies the type of variable whose address this pointer can store. 2. pointer-name : It can be any name specified by the user. Professionally, there are some coding styles which every code follows. The pointer names commonly start with ‘P’ or end with ‘ptr’. Example : char *chptr;
  • 20. ARRAY TYPES • Array is a kind of data structure that can store a fixed- size sequential collection of elements of the same type. • An array is used to store a collection of data, but it is often more useful to think of an array as a collection of variables of the same type. • All arrays consists of contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element. Numbers[0] Numbers[1] Numbers[2] Numbers[3] ….. First Element Last Element
  • 21. How to declare Array? • To declare an array, a programmer specifies the type of the elements and the number of elements required by an array as follows- type arrayName[arraySize]; This is called a single dimensional array. The arraySize must be an integer constant greater than zero and type can be any valid C data type. For example, to declare a 10-element array called balance of type double, use this statement – double balance[10]; Here balance is a variable array which is sufficient to hold up to 10 doubles numbers.
  • 22. STRUCTURE TYPES • Structure is a user defined data the type available in C that allows to combine data items of different kinds. • Structures are used to represent a record. • To define a structure, you must use struct statement. The struct statement defines a new data type, with more than one member.
  • 23. CONTINUED… • The format of the struct statement is as follows- struct [structure tag] { member defination; member defination; …. member defination; } [one or more structure variables];
  • 24. UNION TYPES • A union is a special data type available in C that allows to store different data types in the same memory location. • Unions provide an efficient way of using the same memory location for multi-purpose. • To define a union, you must use a union statement. • The union statement defines a new data type with more than one member for your program.
  • 25. CONTINUED… • The format of the union statement is as follows- union [union tag] { member defination; member defination; …. member defination; }
  • 26. FUNCTION TYPES • A function type describes a function that returns a value of a specified type. • If the function returns no value, it should be declared as “function returning void” as follows: void function1(); • In the following example, the data type for the function is “function returning int”: int uppercase(int lc) { int uc=lc+0x20; return uc; }