SlideShare a Scribd company logo
1 of 26
Definition :-Definition :-
• Arrays are complex variables that can hold multiple
values of the same data type.
• Array is a fixed type sequenced collection of elements of
the same data type.
• It is simply a grouping of like-type data.
• Some examples where a concept of arrays can be used :-
1) List of employees in an organization.
2) Exam scores of a class of students.
3) Table of daily rainfall data.
Origin of the Arrays :-Origin of the Arrays :-
What is the Need of anWhat is the Need of an
Array ?Array ?
• To store large number of variables of same type
under a single variable.
• Easy understanding of the program.
• It provides a convenient structure for
representing data.
• We can use arrays to perform large amounts of
data in smaller values of commands and yet we
can have proper output.
Types of Arrays :-Types of Arrays :-
• There are basically three types of arrays used in a
C programming language :-
1) One-dimensional
2) Two-dimensional
3) Multi-dimensional
One-dimensional arrays :-One-dimensional arrays :-
• The array which is used to represent and store
data in a linear form is called as single or one
dimensional array.
• A structured collection of components all of the
same type, that is given a single name.
• Each component is accessed by an index that
indicates the component’s position within the
collection.
• Array position is always started at 0 and goes up
to one less then the size
Concept :-Concept :-
• Syntax :-
<data_type>
<array_name> [size];
• Total size (in bytes):-
total size = length of
array * size of data type
• The Memory allocation
of the one dimensional
array can be
understood from the
figure.
Declaration of One-Declaration of One-
dimensional arrays :-dimensional arrays :-
• Like any other variable, arrays must be declared before
they are used so that the compiler can allocate space for
them in memory. The general form of array declaration
is :-
type variable name[ size ];
• Here in above syntax ,
1) The type specifies the type of element that will be
contained in the array, such as int, float, or char.
2) The size indicates the maximum number of elements
that can be stored in array.
3) The Variable name indicates the name you want to
assign to the array.
Example :-Example :-
1. float height [50];
In above example, it declares the height to be an
array containing of 50 real elements. Any subjects
from 0 to 49 are valid.
2. int group[10];
In above example, it declares the group as an
array to contain a maximum of 10 integer constants.
Initialization of One-dimensionalInitialization of One-dimensional
Array :-Array :-
• After the array is declared, its elements must be
initialized.
• Otherwise, they will contain junk values.
• An array can be initialized at either of the
following stages :-
1) At compile time
2) At run time
Compile time initialization :-Compile time initialization :-
• Whenever we declare an array, we can initialize
array directly at compile time.
• Initialization of an array is known as compiler
time initialization if and only if we assign certain
set of values to array element before executing
program .i.e. at compilation time.
Explanation :-Explanation :-
• Compiler counts the number of elements written
inside pair of brackets and determines the size of
arrays.
• After counting the number of elements inside the
brackets, the size of an array is declared during
complete execution.
• This type of initialization is called as “Compile
time initialization”.
Example :-Example :-
1. float total [5] = {0.0,15.75,-10}
Here in above example, we initialize the first
three elements to 0.0, 15.75 and -10 and the
remaining two values to zero.
2. char name [ ] = {‘j’, ‘o’, ‘h’, ‘n’, ‘o’}
Here in above example, declares the name to be
an array of five characters, initialized with a string
john ending with the null character.
Run time initialization :-Run time initialization :-
• An array can be explicitly initialized at run time.
• This approach is usually applied for initializing
large arrays.
• Compile-time initialization can only be done
using constant expressions, but run-time
initialization can be done using any expression at
all.
Example :-Example :-
for (i=0; i<100, i=i+1)
{
if i<50
sum [i] = 0.0;
else
sum [i] = 1.0;
}
• Here, the first 50 elements of the array “sum” are
initialized to zero while the remaining 50 elements are
initialized to 1.0 at run time.
Searching and Sorting :-Searching and Sorting :-
• Searching and sorting are two most frequent
operations performed on arrays.
• Computer scientists have devised several data
structures and searching and sorting techniques
that facilitate rapid access to data stored in lists.
• More information on these two concepts are
provided further…..
Searching :-Searching :-
• Searching is a process of finding the location of
the specified element in a list.
• The specified element is often called the search
key.
• If the process of searching finds a match for the
search key with a list element value, the search is
said to be successful, Otherwise it is unsuccessful.
• Types of searching :
1) sequential search
2) binary search
Sorting :-Sorting :-
• Sorting is a process of arranging elements in the
list according to their values, in ascending or
descending order.
• A sorted list is called a ordered list.
• Many sorting techniques are available, but the
most commonly used are 3 techniques :-
1) bubble sort
2) selection sort
3) insertion sort
Two-dimensional arrays :-Two-dimensional arrays :-
• The array which is used to represent and store
data in a tabular form is called as two
dimensional array.
• Such type of array specially used to represent data
in a matrix form.
• Examples:
1) Lab book of multiple readings over
several days
2) Periodic table
3) Movie ratings by multiple reviewers.
- Each row is a different reviewer
- Each column is a different movie
Concept :-Concept :-
• Syntax :-
<data-type>
<array_nm>
[row_subscript]
[column_subscript]
• Memory allocation of
these type of arrays
can be understood
from the figure.
Declaration of Two-DimensionalDeclaration of Two-Dimensional
Arrays :-Arrays :-
• Like any other variable, arrays must be declared before
they are used so that the compiler can allocate space for
them in memory. The general form of array declaration is
type array_name [row_size] [column_size]
• Here in above syntax ,
1) The type specifies the type of element that will be
contained in the array, such as int, float, or char.
2) The size indicates the maximum number of elements that
can be stored columns and rows in array.
3) The Variable_name indicates the name you want to assign
to the array.
Example :-Example :-
Initialization of Two-DimensionalInitialization of Two-Dimensional
Arrays :-Arrays :-
• Like one dimensional arrays, two-dimensional
arrays can be initialized by following their
declaration with a list of initial values enclosed in
brackets.
• Two-dimensional arrays may be initialized by
specifying bracketed values for each row and
column.
Example :-Example :-
Multi-Dimensional Arrays :-Multi-Dimensional Arrays :-
• C allows arrays of three or more dimensions.
• The exact limit is determined by the compiler.
• The general syntax of a multi-dimensional array is
given below :-
type array_name [s1] [s2] [s3]…….[sn];
where ‘s’ is the size of the dimension
• For example,
int survey [3] [5] [12];
float table [5] [6] [7] [8];
Arrays in C - A Complete Guide

More Related Content

What's hot (20)

Array in c programming
Array in c programmingArray in c programming
Array in c programming
 
arrays in c
arrays in carrays in c
arrays in c
 
Abstract Data Types
Abstract Data TypesAbstract Data Types
Abstract Data Types
 
Array
ArrayArray
Array
 
Array ppt
Array pptArray ppt
Array ppt
 
Arrays
ArraysArrays
Arrays
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
 
concept of Array, 1D & 2D array
concept of Array, 1D & 2D arrayconcept of Array, 1D & 2D array
concept of Array, 1D & 2D array
 
sorting and its types
sorting and its typessorting and its types
sorting and its types
 
Array in c language
Array in c languageArray in c language
Array in c language
 
linked list in data structure
linked list in data structure linked list in data structure
linked list in data structure
 
Java Stack Data Structure.pptx
Java Stack Data Structure.pptxJava Stack Data Structure.pptx
Java Stack Data Structure.pptx
 
Programming in c Arrays
Programming in c ArraysProgramming in c Arrays
Programming in c Arrays
 
Introduction to data structure
Introduction to data structureIntroduction to data structure
Introduction to data structure
 
Queues
QueuesQueues
Queues
 
Data Structures in Python
Data Structures in PythonData Structures in Python
Data Structures in Python
 
Graph traversals in Data Structures
Graph traversals in Data StructuresGraph traversals in Data Structures
Graph traversals in Data Structures
 
single linked list
single linked listsingle linked list
single linked list
 
Queue ppt
Queue pptQueue ppt
Queue ppt
 
Array data structure
Array data structureArray data structure
Array data structure
 

Viewers also liked

Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)EngineerBabu
 
Data structure doubly linked list programs
Data structure doubly linked list programsData structure doubly linked list programs
Data structure doubly linked list programsiCreateWorld
 
Doubly circular linked list
Doubly circular linked listDoubly circular linked list
Doubly circular linked listRoshan Chaudhary
 
Doubly Linked List || Operations || Algorithms
Doubly Linked List || Operations || AlgorithmsDoubly Linked List || Operations || Algorithms
Doubly Linked List || Operations || AlgorithmsShubham Sharma
 
Chapter 8 - Multiplexing 9e
Chapter 8 - Multiplexing 9eChapter 8 - Multiplexing 9e
Chapter 8 - Multiplexing 9eadpeer
 
02 Arrays And Memory Mapping
02 Arrays And Memory Mapping02 Arrays And Memory Mapping
02 Arrays And Memory MappingQundeel
 
Chapter23 friend-function-friend-class
Chapter23 friend-function-friend-classChapter23 friend-function-friend-class
Chapter23 friend-function-friend-classDeepak Singh
 
Lecture 2 data structures & algorithms - sorting techniques
Lecture 2  data structures & algorithms - sorting techniquesLecture 2  data structures & algorithms - sorting techniques
Lecture 2 data structures & algorithms - sorting techniquesDharmendra Prasad
 
Object as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younasObject as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younasShahzad Younas
 
Data Structures- Part9 trees simplified
Data Structures- Part9 trees simplifiedData Structures- Part9 trees simplified
Data Structures- Part9 trees simplifiedAbdullah Al-hazmy
 
Data Structures- Part8 stacks and queues
Data Structures- Part8 stacks and queuesData Structures- Part8 stacks and queues
Data Structures- Part8 stacks and queuesAbdullah Al-hazmy
 
Data Structures- Part2 analysis tools
Data Structures- Part2 analysis toolsData Structures- Part2 analysis tools
Data Structures- Part2 analysis toolsAbdullah Al-hazmy
 
Safety rules and earthing
Safety rules and earthingSafety rules and earthing
Safety rules and earthingNikhil Pandit
 
Simplifies and normal forms - Theory of Computation
Simplifies and normal forms - Theory of ComputationSimplifies and normal forms - Theory of Computation
Simplifies and normal forms - Theory of ComputationNikhil Pandit
 

Viewers also liked (20)

Arrays
ArraysArrays
Arrays
 
Lecture 2a arrays
Lecture 2a arraysLecture 2a arrays
Lecture 2a arrays
 
Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)Array Presentation (EngineerBaBu.com)
Array Presentation (EngineerBaBu.com)
 
Team 9
Team 9Team 9
Team 9
 
Data structure doubly linked list programs
Data structure doubly linked list programsData structure doubly linked list programs
Data structure doubly linked list programs
 
Doubly circular linked list
Doubly circular linked listDoubly circular linked list
Doubly circular linked list
 
Java control flow statements
Java control flow statementsJava control flow statements
Java control flow statements
 
Doubly Linked List || Operations || Algorithms
Doubly Linked List || Operations || AlgorithmsDoubly Linked List || Operations || Algorithms
Doubly Linked List || Operations || Algorithms
 
Functions in C++
Functions in C++Functions in C++
Functions in C++
 
Diodes
DiodesDiodes
Diodes
 
Chapter 8 - Multiplexing 9e
Chapter 8 - Multiplexing 9eChapter 8 - Multiplexing 9e
Chapter 8 - Multiplexing 9e
 
02 Arrays And Memory Mapping
02 Arrays And Memory Mapping02 Arrays And Memory Mapping
02 Arrays And Memory Mapping
 
Chapter23 friend-function-friend-class
Chapter23 friend-function-friend-classChapter23 friend-function-friend-class
Chapter23 friend-function-friend-class
 
Lecture 2 data structures & algorithms - sorting techniques
Lecture 2  data structures & algorithms - sorting techniquesLecture 2  data structures & algorithms - sorting techniques
Lecture 2 data structures & algorithms - sorting techniques
 
Object as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younasObject as function argument , friend and static function by shahzad younas
Object as function argument , friend and static function by shahzad younas
 
Data Structures- Part9 trees simplified
Data Structures- Part9 trees simplifiedData Structures- Part9 trees simplified
Data Structures- Part9 trees simplified
 
Data Structures- Part8 stacks and queues
Data Structures- Part8 stacks and queuesData Structures- Part8 stacks and queues
Data Structures- Part8 stacks and queues
 
Data Structures- Part2 analysis tools
Data Structures- Part2 analysis toolsData Structures- Part2 analysis tools
Data Structures- Part2 analysis tools
 
Safety rules and earthing
Safety rules and earthingSafety rules and earthing
Safety rules and earthing
 
Simplifies and normal forms - Theory of Computation
Simplifies and normal forms - Theory of ComputationSimplifies and normal forms - Theory of Computation
Simplifies and normal forms - Theory of Computation
 

Similar to Arrays in C - A Complete Guide

Similar to Arrays in C - A Complete Guide (20)

ARRAYS.pptx
ARRAYS.pptxARRAYS.pptx
ARRAYS.pptx
 
Arrays
ArraysArrays
Arrays
 
Arrays In C Language
Arrays In C LanguageArrays In C Language
Arrays In C Language
 
Arrays.pptx
 Arrays.pptx Arrays.pptx
Arrays.pptx
 
Unit 2 linear data structures
Unit 2   linear data structuresUnit 2   linear data structures
Unit 2 linear data structures
 
Programming fundamentals week 12.pptx
Programming fundamentals week 12.pptxProgramming fundamentals week 12.pptx
Programming fundamentals week 12.pptx
 
Arrays
ArraysArrays
Arrays
 
ch06.ppt
ch06.pptch06.ppt
ch06.ppt
 
ch06.ppt
ch06.pptch06.ppt
ch06.ppt
 
ch06.ppt
ch06.pptch06.ppt
ch06.ppt
 
ch06.ppt
ch06.pptch06.ppt
ch06.ppt
 
array Details
array Detailsarray Details
array Details
 
Chapter-Five.pptx
Chapter-Five.pptxChapter-Five.pptx
Chapter-Five.pptx
 
Lesson 11 one dimensional array
Lesson 11 one dimensional arrayLesson 11 one dimensional array
Lesson 11 one dimensional array
 
Data structure
Data structureData structure
Data structure
 
5 ARRAYS AND STRINGSjiuojhiooioiiouioi.pptx
5 ARRAYS AND STRINGSjiuojhiooioiiouioi.pptx5 ARRAYS AND STRINGSjiuojhiooioiiouioi.pptx
5 ARRAYS AND STRINGSjiuojhiooioiiouioi.pptx
 
Arrays.pptx
Arrays.pptxArrays.pptx
Arrays.pptx
 
java.pdf
java.pdfjava.pdf
java.pdf
 
II B.Sc IT DATA STRUCTURES.pptx
II B.Sc IT DATA STRUCTURES.pptxII B.Sc IT DATA STRUCTURES.pptx
II B.Sc IT DATA STRUCTURES.pptx
 
Unit-4 (Scope Rules and Arrays).pptx for
Unit-4 (Scope Rules and Arrays).pptx forUnit-4 (Scope Rules and Arrays).pptx for
Unit-4 (Scope Rules and Arrays).pptx for
 

More from Nikhil Pandit

Software Coding- Software Coding
Software Coding- Software CodingSoftware Coding- Software Coding
Software Coding- Software CodingNikhil Pandit
 
Use case Diagram and Sequence Diagram
Use case Diagram and Sequence DiagramUse case Diagram and Sequence Diagram
Use case Diagram and Sequence DiagramNikhil Pandit
 
The scope of contribution
The scope of contributionThe scope of contribution
The scope of contributionNikhil Pandit
 
4 stroke diesel engine
4 stroke diesel engine4 stroke diesel engine
4 stroke diesel engineNikhil Pandit
 
CHAIN RULE AND IMPLICIT FUNCTION
CHAIN RULE AND IMPLICIT FUNCTIONCHAIN RULE AND IMPLICIT FUNCTION
CHAIN RULE AND IMPLICIT FUNCTIONNikhil Pandit
 
Register transfer and micro-operation
Register transfer and micro-operationRegister transfer and micro-operation
Register transfer and micro-operationNikhil Pandit
 
Inline Functions and Default arguments
Inline Functions and Default argumentsInline Functions and Default arguments
Inline Functions and Default argumentsNikhil Pandit
 

More from Nikhil Pandit (8)

Software Coding- Software Coding
Software Coding- Software CodingSoftware Coding- Software Coding
Software Coding- Software Coding
 
Use case Diagram and Sequence Diagram
Use case Diagram and Sequence DiagramUse case Diagram and Sequence Diagram
Use case Diagram and Sequence Diagram
 
The scope of contribution
The scope of contributionThe scope of contribution
The scope of contribution
 
4 stroke diesel engine
4 stroke diesel engine4 stroke diesel engine
4 stroke diesel engine
 
CHAIN RULE AND IMPLICIT FUNCTION
CHAIN RULE AND IMPLICIT FUNCTIONCHAIN RULE AND IMPLICIT FUNCTION
CHAIN RULE AND IMPLICIT FUNCTION
 
Register transfer and micro-operation
Register transfer and micro-operationRegister transfer and micro-operation
Register transfer and micro-operation
 
Spyware and rootkit
Spyware and rootkitSpyware and rootkit
Spyware and rootkit
 
Inline Functions and Default arguments
Inline Functions and Default argumentsInline Functions and Default arguments
Inline Functions and Default arguments
 

Recently uploaded

Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 

Recently uploaded (20)

Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 

Arrays in C - A Complete Guide

  • 1.
  • 2. Definition :-Definition :- • Arrays are complex variables that can hold multiple values of the same data type. • Array is a fixed type sequenced collection of elements of the same data type. • It is simply a grouping of like-type data. • Some examples where a concept of arrays can be used :- 1) List of employees in an organization. 2) Exam scores of a class of students. 3) Table of daily rainfall data.
  • 3. Origin of the Arrays :-Origin of the Arrays :-
  • 4. What is the Need of anWhat is the Need of an Array ?Array ? • To store large number of variables of same type under a single variable. • Easy understanding of the program. • It provides a convenient structure for representing data. • We can use arrays to perform large amounts of data in smaller values of commands and yet we can have proper output.
  • 5. Types of Arrays :-Types of Arrays :- • There are basically three types of arrays used in a C programming language :- 1) One-dimensional 2) Two-dimensional 3) Multi-dimensional
  • 6. One-dimensional arrays :-One-dimensional arrays :- • The array which is used to represent and store data in a linear form is called as single or one dimensional array. • A structured collection of components all of the same type, that is given a single name. • Each component is accessed by an index that indicates the component’s position within the collection. • Array position is always started at 0 and goes up to one less then the size
  • 7. Concept :-Concept :- • Syntax :- <data_type> <array_name> [size]; • Total size (in bytes):- total size = length of array * size of data type • The Memory allocation of the one dimensional array can be understood from the figure.
  • 8. Declaration of One-Declaration of One- dimensional arrays :-dimensional arrays :- • Like any other variable, arrays must be declared before they are used so that the compiler can allocate space for them in memory. The general form of array declaration is :- type variable name[ size ]; • Here in above syntax , 1) The type specifies the type of element that will be contained in the array, such as int, float, or char. 2) The size indicates the maximum number of elements that can be stored in array. 3) The Variable name indicates the name you want to assign to the array.
  • 9. Example :-Example :- 1. float height [50]; In above example, it declares the height to be an array containing of 50 real elements. Any subjects from 0 to 49 are valid. 2. int group[10]; In above example, it declares the group as an array to contain a maximum of 10 integer constants.
  • 10. Initialization of One-dimensionalInitialization of One-dimensional Array :-Array :- • After the array is declared, its elements must be initialized. • Otherwise, they will contain junk values. • An array can be initialized at either of the following stages :- 1) At compile time 2) At run time
  • 11. Compile time initialization :-Compile time initialization :- • Whenever we declare an array, we can initialize array directly at compile time. • Initialization of an array is known as compiler time initialization if and only if we assign certain set of values to array element before executing program .i.e. at compilation time.
  • 12. Explanation :-Explanation :- • Compiler counts the number of elements written inside pair of brackets and determines the size of arrays. • After counting the number of elements inside the brackets, the size of an array is declared during complete execution. • This type of initialization is called as “Compile time initialization”.
  • 13. Example :-Example :- 1. float total [5] = {0.0,15.75,-10} Here in above example, we initialize the first three elements to 0.0, 15.75 and -10 and the remaining two values to zero. 2. char name [ ] = {‘j’, ‘o’, ‘h’, ‘n’, ‘o’} Here in above example, declares the name to be an array of five characters, initialized with a string john ending with the null character.
  • 14. Run time initialization :-Run time initialization :- • An array can be explicitly initialized at run time. • This approach is usually applied for initializing large arrays. • Compile-time initialization can only be done using constant expressions, but run-time initialization can be done using any expression at all.
  • 15. Example :-Example :- for (i=0; i<100, i=i+1) { if i<50 sum [i] = 0.0; else sum [i] = 1.0; } • Here, the first 50 elements of the array “sum” are initialized to zero while the remaining 50 elements are initialized to 1.0 at run time.
  • 16. Searching and Sorting :-Searching and Sorting :- • Searching and sorting are two most frequent operations performed on arrays. • Computer scientists have devised several data structures and searching and sorting techniques that facilitate rapid access to data stored in lists. • More information on these two concepts are provided further…..
  • 17. Searching :-Searching :- • Searching is a process of finding the location of the specified element in a list. • The specified element is often called the search key. • If the process of searching finds a match for the search key with a list element value, the search is said to be successful, Otherwise it is unsuccessful. • Types of searching : 1) sequential search 2) binary search
  • 18. Sorting :-Sorting :- • Sorting is a process of arranging elements in the list according to their values, in ascending or descending order. • A sorted list is called a ordered list. • Many sorting techniques are available, but the most commonly used are 3 techniques :- 1) bubble sort 2) selection sort 3) insertion sort
  • 19. Two-dimensional arrays :-Two-dimensional arrays :- • The array which is used to represent and store data in a tabular form is called as two dimensional array. • Such type of array specially used to represent data in a matrix form. • Examples: 1) Lab book of multiple readings over several days 2) Periodic table 3) Movie ratings by multiple reviewers. - Each row is a different reviewer - Each column is a different movie
  • 20. Concept :-Concept :- • Syntax :- <data-type> <array_nm> [row_subscript] [column_subscript] • Memory allocation of these type of arrays can be understood from the figure.
  • 21. Declaration of Two-DimensionalDeclaration of Two-Dimensional Arrays :-Arrays :- • Like any other variable, arrays must be declared before they are used so that the compiler can allocate space for them in memory. The general form of array declaration is type array_name [row_size] [column_size] • Here in above syntax , 1) The type specifies the type of element that will be contained in the array, such as int, float, or char. 2) The size indicates the maximum number of elements that can be stored columns and rows in array. 3) The Variable_name indicates the name you want to assign to the array.
  • 23. Initialization of Two-DimensionalInitialization of Two-Dimensional Arrays :-Arrays :- • Like one dimensional arrays, two-dimensional arrays can be initialized by following their declaration with a list of initial values enclosed in brackets. • Two-dimensional arrays may be initialized by specifying bracketed values for each row and column.
  • 25. Multi-Dimensional Arrays :-Multi-Dimensional Arrays :- • C allows arrays of three or more dimensions. • The exact limit is determined by the compiler. • The general syntax of a multi-dimensional array is given below :- type array_name [s1] [s2] [s3]…….[sn]; where ‘s’ is the size of the dimension • For example, int survey [3] [5] [12]; float table [5] [6] [7] [8];