ARRAYS IN C
PROGRAMMING
TABLE OF CONTENTS
Introduction
Why do we need arrays?
Accessing element in arrays
Example
Type of arrays
Advantages
Disadvantages
Conclusion
INTRODUCTION
An array in C is a fixed-size collection of
similar data items stored in contiguous
memory locations. It can be used to store
the collection of primitive data types
such as int, char, float, etc., and also
derived and user-defined data types
such as pointers, structures, etc.
01
WHY DO WE NEED
ARRAYS?
Array stores an extensive collection of similar data types. We have only
three variables, and then we can easily store them using separate
names like int var1, int var2, and int var3, but what if we have an
extensive collection of these variables? Then, we cannot assign
separate names to each of them, as it would be tedious and time-
consuming.
02
Accessing Elements in Arrays
You can easily access elements in an
Array using their index. Suppose we
want to access the element at the third
index of our array. Then, we can easily
do it using arr[2], which is size-1.
int arr[6] = {1, 4, 8, 25, 2, 17};
What is CRM
printf (“%d”, arr[2]); // Accessing the third
element at index 2, which is 8
06
Example of Array in C
07
TYPES OF ARRAY
1. One-Dimensional 2. Multi-
Array Dimensional Array
This is also known as a 1-D array as it is This is also known as a multidimensional array
only having one dimension. because they have more than one dimension.
name_of_Array [ size ]; name_of_Array [ size ] [ size2 ];
08
ADVANTAGES
[Link] memory usage: Arrays allocate contiguous memory blocks, reducing
memory overhead.
[Link] syntax: Declaring and accessing elements in arrays is straightforward in C.
[Link] access: Array elements are accessed via index, providing direct memory access
and faster retrieval.
[Link] data storage: Arrays store elements of the same data type, ensuring
uniformity.
08
DISADVANTAGES
[Link] size: Once declared, array sizes cannot be changed dynamically, limiting
flexibility.
[Link] resizing: Resizing arrays requires manual shifting or recreating, leading to
inefficiency.
[Link] functionality: Arrays lack built-in functions for common operations like
sorting or searching.
[Link] bounds checking: C arrays don't enforce bounds, risking errors if accessing
elements beyond the declared size.
08
Conclusion
In conclusion, while arrays in C provide
a simple and efficient way to store data,
they come with limitations such as fixed
size, lack of bounds checking, complex
memory management, absence of built-
in resize operations, and potential
performance overhead when passed to
functions.
09
THANK YOU
FOR YOUR ATTENTION