SlideShare a Scribd company logo
1 of 9
Programming Methodologies
Arrays
Array
● An array is defined as the collection of similar type of
data items stored at contiguous memory locations.
● The array is the simplest data structure where each
data element can be randomly accessed by using its
index number.
● Each element of an array is of same data type and
carries the same size, i.e., int = 4 bytes.
● Elements of the array are stored at contiguous memory
locations where the first element is stored at the smallest
memory location.
● Elements of the array can be randomly accessed since we
can calculate the address of each element of the array
with the given base address and the size of the data
element.
Array Declaration
● Syntax:
○ dataType arrayName[arraySize];
○ int mark[5];
● Size is 5 - It can hold 5 integer values.
mark[0] mark[1] mark[2] mark[3] mark[4]
0 1 2 3 4
Indexes
First Element Last Element
Array Initialization
Example:
● int mark[5] = {19, 10, 8, 17, 9};
OR
● int mark[] = {19, 10, 8, 17, 9};
● No need to specify the size. The compiler knows its size is 5 as we are initializing it
with 5 elements.
Multidimensional Arrays
2D Array
● Syntax:
○ dataType arrayName[numberOfRows] [numberOfColumns];
○ Example:
○ int marks [2][3];
○ Can Store 6 values.
0 1 2
0 mark[0][0] mark[0][1] mark[0][2]
1 mark[1][0] mark[1][1] mark[1][2]
Column Indexes
Row
Indexes
2D Array Initialization
Example:
● int mark[2][3] = { {75,65,96} , {34,72,56} };
OR
● int mark[][3] = { {75,65,96} , {34,72,56} };
○ Need to specify the number of columns. The number of rows can be inferred
from the initializer list.
Advantages of C Array
● Code Optimization : Less code to the access the data.
● Ease of traversing : By using the for loop, we can retrieve the
elements of an array easily.
● Random Access : We can access any element randomly using the
array.
Disadvantages of C Array
● Fixed Size:
○ Arrays have a fixed size, the number of elements is specified when they are declared.
● Limited Data Types:
○ Arrays usually store elements of a single data type. If you need to store different data
types in a collection, you would either need to create separate arrays for each data type
or use a more complex data structure.
● Insertion and Deletion:
○ Inserting or deleting elements in an array can be inefficient and time-consuming,
especially if the array is large or if the insertion/deletion occurs at the beginning or
middle of the array.

More Related Content

Similar to Basic Arrays in C Programming Language I

Programming fundamentals week 12.pptx
Programming fundamentals week 12.pptxProgramming fundamentals week 12.pptx
Programming fundamentals week 12.pptx
dfsdg3
 

Similar to Basic Arrays in C Programming Language I (20)

Array
ArrayArray
Array
 
Arrays
ArraysArrays
Arrays
 
Arrays accessing using for loops
Arrays accessing using for loopsArrays accessing using for loops
Arrays accessing using for loops
 
Programming fundamentals week 12.pptx
Programming fundamentals week 12.pptxProgramming fundamentals week 12.pptx
Programming fundamentals week 12.pptx
 
Basic of array and data structure, data structure basics, array, address calc...
Basic of array and data structure, data structure basics, array, address calc...Basic of array and data structure, data structure basics, array, address calc...
Basic of array and data structure, data structure basics, array, address calc...
 
arrays.pptx
arrays.pptxarrays.pptx
arrays.pptx
 
Lecture17 arrays.ppt
Lecture17 arrays.pptLecture17 arrays.ppt
Lecture17 arrays.ppt
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 
Arrays
ArraysArrays
Arrays
 
Numpy.pdf
Numpy.pdfNumpy.pdf
Numpy.pdf
 
Array in C full basic explanation
Array in C full basic explanationArray in C full basic explanation
Array in C full basic explanation
 
PPt. on An _Array in C
PPt. on An _Array in CPPt. on An _Array in C
PPt. on An _Array in C
 
javaarray
javaarrayjavaarray
javaarray
 
Arrays In C Language
Arrays In C LanguageArrays In C Language
Arrays In C Language
 
Arrays.pptx
Arrays.pptxArrays.pptx
Arrays.pptx
 
Arrays in C.pptx
Arrays in C.pptxArrays in C.pptx
Arrays in C.pptx
 
7array in c#
7array in c#7array in c#
7array in c#
 
Unit 4
Unit 4Unit 4
Unit 4
 
Mesics lecture 8 arrays in 'c'
Mesics lecture 8   arrays in 'c'Mesics lecture 8   arrays in 'c'
Mesics lecture 8 arrays in 'c'
 
Arrays & Strings
Arrays & StringsArrays & Strings
Arrays & Strings
 

Recently uploaded

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 

Recently uploaded (20)

HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptx
 
Introduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfIntroduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdf
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 
Post office management system project ..pdf
Post office management system project ..pdfPost office management system project ..pdf
Post office management system project ..pdf
 
Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...
Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...
Convergence of Robotics and Gen AI offers excellent opportunities for Entrepr...
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Augmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptxAugmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptx
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Introduction to Geographic Information Systems
Introduction to Geographic Information SystemsIntroduction to Geographic Information Systems
Introduction to Geographic Information Systems
 
Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...Basic Electronics for diploma students as per technical education Kerala Syll...
Basic Electronics for diploma students as per technical education Kerala Syll...
 
fitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .pptfitting shop and tools used in fitting shop .ppt
fitting shop and tools used in fitting shop .ppt
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Memory Interfacing of 8086 with DMA 8257
Memory Interfacing of 8086 with DMA 8257Memory Interfacing of 8086 with DMA 8257
Memory Interfacing of 8086 with DMA 8257
 

Basic Arrays in C Programming Language I

  • 2. Array ● An array is defined as the collection of similar type of data items stored at contiguous memory locations. ● The array is the simplest data structure where each data element can be randomly accessed by using its index number. ● Each element of an array is of same data type and carries the same size, i.e., int = 4 bytes.
  • 3. ● Elements of the array are stored at contiguous memory locations where the first element is stored at the smallest memory location. ● Elements of the array can be randomly accessed since we can calculate the address of each element of the array with the given base address and the size of the data element.
  • 4. Array Declaration ● Syntax: ○ dataType arrayName[arraySize]; ○ int mark[5]; ● Size is 5 - It can hold 5 integer values. mark[0] mark[1] mark[2] mark[3] mark[4] 0 1 2 3 4 Indexes First Element Last Element
  • 5. Array Initialization Example: ● int mark[5] = {19, 10, 8, 17, 9}; OR ● int mark[] = {19, 10, 8, 17, 9}; ● No need to specify the size. The compiler knows its size is 5 as we are initializing it with 5 elements.
  • 6. Multidimensional Arrays 2D Array ● Syntax: ○ dataType arrayName[numberOfRows] [numberOfColumns]; ○ Example: ○ int marks [2][3]; ○ Can Store 6 values. 0 1 2 0 mark[0][0] mark[0][1] mark[0][2] 1 mark[1][0] mark[1][1] mark[1][2] Column Indexes Row Indexes
  • 7. 2D Array Initialization Example: ● int mark[2][3] = { {75,65,96} , {34,72,56} }; OR ● int mark[][3] = { {75,65,96} , {34,72,56} }; ○ Need to specify the number of columns. The number of rows can be inferred from the initializer list.
  • 8. Advantages of C Array ● Code Optimization : Less code to the access the data. ● Ease of traversing : By using the for loop, we can retrieve the elements of an array easily. ● Random Access : We can access any element randomly using the array.
  • 9. Disadvantages of C Array ● Fixed Size: ○ Arrays have a fixed size, the number of elements is specified when they are declared. ● Limited Data Types: ○ Arrays usually store elements of a single data type. If you need to store different data types in a collection, you would either need to create separate arrays for each data type or use a more complex data structure. ● Insertion and Deletion: ○ Inserting or deleting elements in an array can be inefficient and time-consuming, especially if the array is large or if the insertion/deletion occurs at the beginning or middle of the array.