SlideShare a Scribd company logo
1 of 25
CSPC-COMPUTER SYSTEMS
PROGRAMMING IN ‘C’
ANKUR SRIVASTAVA
DEPARTMENT OF COMPUTER SCIENCE
08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI
1
ARRAYS: ARRAY NOTATION AND REPRESENTATION,
MANIPULATING ARRAY ELEMENTS, USING MULTI-
DIMENSIONAL ARRAYS.
STRUCTURE, UNION, ENUMERATED DATA TYPES.
UNIT-4 TOPICS
08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI
2
UNIT-4 ARRAYS
 An arrayarray is a named collection of homogeneous items in which
individual items are accessed by their place within the collection.
 An arrayarray is a collection of variables of the same type that are referred
to by a common name.
Eg.
 product part numbers:
int part numbers[] = {123, 326, 178, 1209};
 student scores:
int scores[10] = {1, 3, 4, 5, 1, 3, 2, 3, 4, 4};
 characters:
char alphabet[5] = {’A’, ’B’, ’C’, ’D’, ’E’};
08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI
3
INITIALIZATION OF ARRAY
 Array – a set of elements all of the same type stored contiguously
in memory – e.g.,
 int A[25]; // 25 integers
 struct Str B[15]; /* 15 objects of
type struct Str */
 double C[]; /* indeterminate #
of doubles */
08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI
4
ARRAY NOTATION
08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI
5
An array of size N is indexed from zero to N-1
79 87 94 82 67 98 87 81 74 91scores
The entire array
has a single name
Each value has a numeric index
This array holds 10 values that are indexed from 0 to 9
MANIPULATING ARRAY ELEMENTS
 Some other examples of array declarations:
float[] prices = new float[500];
boolean[] flags;
flags = new boolean[20];
char[] codes = new char[1750];
08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI
6
2D ARRAY
08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI
7
 A one-dimensional array stores a list of elements
 A two-dimensional array can be thought of as a table of
elements, with rows and columns
one
dimension
two
dimensions
3D ARRAY
08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI
8
An array can be declared with multiple dimensions.
2 Dimensional 3 Dimensional
Multiple dimensions get difficult to visualize graphically.
•
int [][][] table3 = { { {1,2}, {3,4} },
{ {5,6,7} , {8}, {9,10}
}
};
USING MULTI-DIMENSIONAL ARRAYS
 An array can have many dimensions – if it has more than one
dimension, it is called a multidimensional array
 Each dimension subdivides the previous one into the specified
number of elements
 Each dimension has its own length constant
 Because each dimension is an array of array references, the
arrays within one dimension can be of different lengths
 these are sometimes called ragged arrays
08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI
9
MULTIDIMENSIONAL ARRAY
 Arrays with more than one index
 number of dimensions = number of indexes
 Arrays with more than two dimensions are a simple extension of
two-dimensional (2-D) arrays
 A 2-D array corresponds to a table or grid
 one dimension is the row
 the other dimension is the column
 cell: an intersection of a row and column
 an array element corresponds to a cell in the table
08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI
10
MULTI ARRAYS IMAGES
08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI
11
STRUCTURE:
 A structure is a collection of one or more components (members).
 Structures are called records in many other programming languages.
 Members are known as fields.
Declaring a structure:-
struct {
char name[25];
int id, age;
char sex;
} s1, s2;
08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI
12
INITIALIZING A STRUCTURE:-
struct {
char name[25];
int id, age;
char sex;
}
s1 = { "Smith, John", 2813, 25, 'M'},
s 2 = { "Smith, Mary", 4692, 23, 'F'};
08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI
13
ACCESSING THE MEMBERS OF A STRUCTURE:
 The members of a structure are accessed by writing first the name
of the structure, then a period, then the name of the member:
struct student {
char name[25];
int id, age;
char sex;
} s;
strcpy(s.name, "Doe, John");
s.id = 18193;
s.age = 18;
s.sex = 'M';
08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI
14
Some More Examples
08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI
15
Contd…..
08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI
16
INITIALIZATION OF STRUCTURE ARRAYS
 Structure arrays are initialized by enclosing the list of values of its
elements within a pair of braces.
 Example:
struct unit
{ char ch ;
int i ;
} ;
struct unit series [3]=
{ (‘a’, 100) (‘b’, 200) (‘c’, 400)
};
08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI
17
UNION:
 A union is similar to a structure, except that its members are
overlaid (located at the same memory address).
 A union is like a structure in which all members are stored at the
same address.
 Example:
union {
int i;
double d;
} u;
08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI
18
ACCESSING THE MEMBER
 The members of a union are accessed in the same way as members of
a structure:
u.i = 15;
or
u.d = 8.89;
Since u.i and u.d have the same memory address, changing the value
of one alters the value of the other.
08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI
19
Difference Between Structure & Union
08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI
20
// declaring structure
struct struct_example
{
int integer;
float decimal;
char name[20];
};
// declaring union  
union union_example
{
    int integer;
    float decimal;
    char name[20];
};
Contd….
08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI
21
DIFFERENCE IN STORAGE OF UNION AND
STRUCTURE
08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI
22
Contd……..
08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI
23
ENUMERATED DATA TYPES
08/11/18
ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI
24
ENUM DATA TYPES
08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI
25

More Related Content

What's hot

Data structure
Data structureData structure
Data structureMohd Arif
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structuresunilchute1
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structureZaid Shabbir
 
Introduction to Data Structure part 1
Introduction to Data Structure part 1Introduction to Data Structure part 1
Introduction to Data Structure part 1ProfSonaliGholveDoif
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsAakash deep Singhal
 
introduction to Data Structure and classification
 introduction to Data Structure and classification introduction to Data Structure and classification
introduction to Data Structure and classificationchauhankapil
 
Mca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structureMca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structureRai University
 
Lecture 01 Intro to DSA
Lecture 01 Intro to DSALecture 01 Intro to DSA
Lecture 01 Intro to DSANurjahan Nipa
 
Data Compression in Data mining and Business Intelligencs
Data Compression in Data mining and Business Intelligencs Data Compression in Data mining and Business Intelligencs
Data Compression in Data mining and Business Intelligencs ShahDhruv21
 
Variables & Data Types in R
Variables & Data Types in RVariables & Data Types in R
Variables & Data Types in RRsquared Academy
 
Introduction of Data Structure
Introduction of Data StructureIntroduction of Data Structure
Introduction of Data StructureMandavi Classes
 
Elementary data organisation
Elementary data organisationElementary data organisation
Elementary data organisationMuzamil Hussain
 

What's hot (20)

Abstract data types
Abstract data typesAbstract data types
Abstract data types
 
Data structure
Data structureData structure
Data structure
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structure
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structure
 
Introduction to Data Structure part 1
Introduction to Data Structure part 1Introduction to Data Structure part 1
Introduction to Data Structure part 1
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithms
 
introduction to Data Structure and classification
 introduction to Data Structure and classification introduction to Data Structure and classification
introduction to Data Structure and classification
 
Mca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structureMca ii dfs u-1 introduction to data structure
Mca ii dfs u-1 introduction to data structure
 
R data types
R data typesR data types
R data types
 
Lecture 01 Intro to DSA
Lecture 01 Intro to DSALecture 01 Intro to DSA
Lecture 01 Intro to DSA
 
Array
ArrayArray
Array
 
Data structure and its types.
Data structure and its types.Data structure and its types.
Data structure and its types.
 
Data structure
Data structureData structure
Data structure
 
Computer Science-Data Structures :Abstract DataType (ADT)
Computer Science-Data Structures :Abstract DataType (ADT)Computer Science-Data Structures :Abstract DataType (ADT)
Computer Science-Data Structures :Abstract DataType (ADT)
 
Data structures
Data structuresData structures
Data structures
 
Data Compression in Data mining and Business Intelligencs
Data Compression in Data mining and Business Intelligencs Data Compression in Data mining and Business Intelligencs
Data Compression in Data mining and Business Intelligencs
 
Variables & Data Types in R
Variables & Data Types in RVariables & Data Types in R
Variables & Data Types in R
 
Introduction of Data Structure
Introduction of Data StructureIntroduction of Data Structure
Introduction of Data Structure
 
Introduction linked list
Introduction linked listIntroduction linked list
Introduction linked list
 
Elementary data organisation
Elementary data organisationElementary data organisation
Elementary data organisation
 

Similar to Unit 4 cspc

Similar to Unit 4 cspc (20)

Algorithm and Data Structure - Array and Struct
Algorithm and Data Structure - Array and StructAlgorithm and Data Structure - Array and Struct
Algorithm and Data Structure - Array and Struct
 
Array in C
Array in CArray in C
Array in C
 
Class notes(week 4) on arrays and strings
Class notes(week 4) on arrays and stringsClass notes(week 4) on arrays and strings
Class notes(week 4) on arrays and strings
 
Arrays
ArraysArrays
Arrays
 
ARRAYSCPP.pptx
ARRAYSCPP.pptxARRAYSCPP.pptx
ARRAYSCPP.pptx
 
Arrays
ArraysArrays
Arrays
 
Java arrays
Java arraysJava arrays
Java arrays
 
Class notes(week 4) on arrays and strings
Class notes(week 4) on arrays and stringsClass notes(week 4) on arrays and strings
Class notes(week 4) on arrays and strings
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
Array 2 hina
Array 2 hina Array 2 hina
Array 2 hina
 
Unit4 Slides
Unit4 SlidesUnit4 Slides
Unit4 Slides
 
array-191103180006.pdf
array-191103180006.pdfarray-191103180006.pdf
array-191103180006.pdf
 
1. structure
1. structure1. structure
1. structure
 
Structure in C
Structure in CStructure in C
Structure in C
 
Structure in C language
Structure in C languageStructure in C language
Structure in C language
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
 
arrays in c# including Classes handling arrays
arrays in c#  including Classes handling arraysarrays in c#  including Classes handling arrays
arrays in c# including Classes handling arrays
 
Pooja
PoojaPooja
Pooja
 
Pooja
PoojaPooja
Pooja
 
arrays.docx
arrays.docxarrays.docx
arrays.docx
 

More from BBDITM LUCKNOW (20)

Unit 5 cspc
Unit 5 cspcUnit 5 cspc
Unit 5 cspc
 
Unit3 cspc
Unit3 cspcUnit3 cspc
Unit3 cspc
 
Cse ppt 2018
Cse ppt 2018Cse ppt 2018
Cse ppt 2018
 
Binary system ppt
Binary system pptBinary system ppt
Binary system ppt
 
Unit 4 ca-input-output
Unit 4 ca-input-outputUnit 4 ca-input-output
Unit 4 ca-input-output
 
Unit 3 ca-memory
Unit 3 ca-memoryUnit 3 ca-memory
Unit 3 ca-memory
 
Unit 2 ca- control unit
Unit 2 ca- control unitUnit 2 ca- control unit
Unit 2 ca- control unit
 
Unit 1 ca-introduction
Unit 1 ca-introductionUnit 1 ca-introduction
Unit 1 ca-introduction
 
Yacc
YaccYacc
Yacc
 
Bnf and ambiquity
Bnf and ambiquityBnf and ambiquity
Bnf and ambiquity
 
Lex
LexLex
Lex
 
Minimization of dfa
Minimization of dfaMinimization of dfa
Minimization of dfa
 
Passescd
PassescdPassescd
Passescd
 
Compiler unit 4
Compiler unit 4Compiler unit 4
Compiler unit 4
 
Compiler unit 2&3
Compiler unit 2&3Compiler unit 2&3
Compiler unit 2&3
 
Compiler unit 1
Compiler unit 1Compiler unit 1
Compiler unit 1
 
Compiler unit 5
Compiler  unit 5Compiler  unit 5
Compiler unit 5
 
Cspc final
Cspc finalCspc final
Cspc final
 
Cd2 [autosaved]
Cd2 [autosaved]Cd2 [autosaved]
Cd2 [autosaved]
 
Validation based protocol
Validation based protocolValidation based protocol
Validation based protocol
 

Recently uploaded

Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 

Recently uploaded (20)

Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 

Unit 4 cspc

  • 1. CSPC-COMPUTER SYSTEMS PROGRAMMING IN ‘C’ ANKUR SRIVASTAVA DEPARTMENT OF COMPUTER SCIENCE 08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI 1
  • 2. ARRAYS: ARRAY NOTATION AND REPRESENTATION, MANIPULATING ARRAY ELEMENTS, USING MULTI- DIMENSIONAL ARRAYS. STRUCTURE, UNION, ENUMERATED DATA TYPES. UNIT-4 TOPICS 08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI 2
  • 3. UNIT-4 ARRAYS  An arrayarray is a named collection of homogeneous items in which individual items are accessed by their place within the collection.  An arrayarray is a collection of variables of the same type that are referred to by a common name. Eg.  product part numbers: int part numbers[] = {123, 326, 178, 1209};  student scores: int scores[10] = {1, 3, 4, 5, 1, 3, 2, 3, 4, 4};  characters: char alphabet[5] = {’A’, ’B’, ’C’, ’D’, ’E’}; 08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI 3
  • 4. INITIALIZATION OF ARRAY  Array – a set of elements all of the same type stored contiguously in memory – e.g.,  int A[25]; // 25 integers  struct Str B[15]; /* 15 objects of type struct Str */  double C[]; /* indeterminate # of doubles */ 08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI 4
  • 5. ARRAY NOTATION 08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI 5 An array of size N is indexed from zero to N-1 79 87 94 82 67 98 87 81 74 91scores The entire array has a single name Each value has a numeric index This array holds 10 values that are indexed from 0 to 9
  • 6. MANIPULATING ARRAY ELEMENTS  Some other examples of array declarations: float[] prices = new float[500]; boolean[] flags; flags = new boolean[20]; char[] codes = new char[1750]; 08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI 6
  • 7. 2D ARRAY 08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI 7  A one-dimensional array stores a list of elements  A two-dimensional array can be thought of as a table of elements, with rows and columns one dimension two dimensions
  • 8. 3D ARRAY 08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI 8 An array can be declared with multiple dimensions. 2 Dimensional 3 Dimensional Multiple dimensions get difficult to visualize graphically. • int [][][] table3 = { { {1,2}, {3,4} }, { {5,6,7} , {8}, {9,10} } };
  • 9. USING MULTI-DIMENSIONAL ARRAYS  An array can have many dimensions – if it has more than one dimension, it is called a multidimensional array  Each dimension subdivides the previous one into the specified number of elements  Each dimension has its own length constant  Because each dimension is an array of array references, the arrays within one dimension can be of different lengths  these are sometimes called ragged arrays 08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI 9
  • 10. MULTIDIMENSIONAL ARRAY  Arrays with more than one index  number of dimensions = number of indexes  Arrays with more than two dimensions are a simple extension of two-dimensional (2-D) arrays  A 2-D array corresponds to a table or grid  one dimension is the row  the other dimension is the column  cell: an intersection of a row and column  an array element corresponds to a cell in the table 08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI 10
  • 11. MULTI ARRAYS IMAGES 08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI 11
  • 12. STRUCTURE:  A structure is a collection of one or more components (members).  Structures are called records in many other programming languages.  Members are known as fields. Declaring a structure:- struct { char name[25]; int id, age; char sex; } s1, s2; 08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI 12
  • 13. INITIALIZING A STRUCTURE:- struct { char name[25]; int id, age; char sex; } s1 = { "Smith, John", 2813, 25, 'M'}, s 2 = { "Smith, Mary", 4692, 23, 'F'}; 08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI 13
  • 14. ACCESSING THE MEMBERS OF A STRUCTURE:  The members of a structure are accessed by writing first the name of the structure, then a period, then the name of the member: struct student { char name[25]; int id, age; char sex; } s; strcpy(s.name, "Doe, John"); s.id = 18193; s.age = 18; s.sex = 'M'; 08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI 14
  • 15. Some More Examples 08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI 15
  • 17. INITIALIZATION OF STRUCTURE ARRAYS  Structure arrays are initialized by enclosing the list of values of its elements within a pair of braces.  Example: struct unit { char ch ; int i ; } ; struct unit series [3]= { (‘a’, 100) (‘b’, 200) (‘c’, 400) }; 08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI 17
  • 18. UNION:  A union is similar to a structure, except that its members are overlaid (located at the same memory address).  A union is like a structure in which all members are stored at the same address.  Example: union { int i; double d; } u; 08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI 18
  • 19. ACCESSING THE MEMBER  The members of a union are accessed in the same way as members of a structure: u.i = 15; or u.d = 8.89; Since u.i and u.d have the same memory address, changing the value of one alters the value of the other. 08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI 19
  • 20. Difference Between Structure & Union 08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI 20 // declaring structure struct struct_example { int integer; float decimal; char name[20]; }; // declaring union   union union_example {     int integer;     float decimal;     char name[20]; };
  • 22. DIFFERENCE IN STORAGE OF UNION AND STRUCTURE 08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI 22
  • 24. ENUMERATED DATA TYPES 08/11/18 ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI 24
  • 25. ENUM DATA TYPES 08/11/18ANKUR SRIVASTAVA ASSISTANT PROFESSOR JETGI 25