1.1 Arrays in Data Structure | Declaration, Initialization,
Memory representation
Introduction to Arrays and Memory Representation
Topic: Limitations and Drawbacks of Static Arrays
Key Concepts:
Static Array Declaration and Initialization
Fixed Size
Waste of Memory
Initialization Overhead
Static Array Declaration and Initialization
Declare and initialize an array with a fixed size
Examples:
int arr[5];
char name[10] = "John Doe";
Fixed Size
Size of a static array cannot be changed once
declared
Can lead to limitations when handling data of
varying sizes
Waste of Memory
If not all elements in the array are used, it results in
memory wastage
, Ex: Declaring an array of size 10 when only 5
elements are required
Initialization Overhead
Static arrays must be initialized with a specific
value before use
If the array is large, it can lead to significant
overhead in terms of time and resources
Note: These limitations of static arrays make them less
flexible compared to dynamic arrays, which can resize as
needed and reduce memory wastage.
Declaration and Initialization of Arrays
Declaration and Initialization of Arrays
Introduction
Arrays are a fundamental data structure in computer
programming, used to store collections of data of the
same type. In this note, we will focus on the declaration
and initialization of arrays, as well as their limitations and
drawbacks.
Declaration and Initialization
An array can be declared using the following syntax:
dataType arrayName[arraySize];
where dataType is the type of data that the array will
hold, arrayName is the name given to the array,
and arraySize is the number of elements the array can
hold.
Memory representation
Introduction to Arrays and Memory Representation
Topic: Limitations and Drawbacks of Static Arrays
Key Concepts:
Static Array Declaration and Initialization
Fixed Size
Waste of Memory
Initialization Overhead
Static Array Declaration and Initialization
Declare and initialize an array with a fixed size
Examples:
int arr[5];
char name[10] = "John Doe";
Fixed Size
Size of a static array cannot be changed once
declared
Can lead to limitations when handling data of
varying sizes
Waste of Memory
If not all elements in the array are used, it results in
memory wastage
, Ex: Declaring an array of size 10 when only 5
elements are required
Initialization Overhead
Static arrays must be initialized with a specific
value before use
If the array is large, it can lead to significant
overhead in terms of time and resources
Note: These limitations of static arrays make them less
flexible compared to dynamic arrays, which can resize as
needed and reduce memory wastage.
Declaration and Initialization of Arrays
Declaration and Initialization of Arrays
Introduction
Arrays are a fundamental data structure in computer
programming, used to store collections of data of the
same type. In this note, we will focus on the declaration
and initialization of arrays, as well as their limitations and
drawbacks.
Declaration and Initialization
An array can be declared using the following syntax:
dataType arrayName[arraySize];
where dataType is the type of data that the array will
hold, arrayName is the name given to the array,
and arraySize is the number of elements the array can
hold.