Search for notes by fellow students, in your own course and all over the country.
Browse our notes for titles which look like what you need, you can preview any of the notes via a sample of the contents. After you're happy these are the notes you're after simply pop them into your shopping cart.
Title: Arrays in Data Structure | Declaration, Initialization, Memory representation
Description: Arrays in Data Structure | Declaration, Initialization, Memory representation Jenny's Lectures CS IT Understanding Memory and Arrays in Programming
Description: Arrays in Data Structure | Declaration, Initialization, Memory representation Jenny's Lectures CS IT Understanding Memory and Arrays in Programming
Document Preview
Extracts from the notes are below, to see the PDF you'll receive please use the links above
1
...
This can be
extended to both sides, making it open-ended
...
Storing Values in Memory
To store a value in memory, we need to know how much space will be allocated for it
...
The number 5 would need to be converted to bin
ary, which is 32 bits or 4 bytes
...
So, if we were storing an integer, it would take up 2-4 bytes in memory
...
For example, the value stored in a variable could be 5, which would be r
epresented as 101 in binary
...
For example, an array of charact
ers would be of the data type char, and an array of integers would be of the data type int
...
To declare an array in programming, we use a specific syntax
...
To declare an array, we would use:
int a[16];
This creates an array called "a" with 16 elements
...
For example, we could initialize an array of integers with the val
ues 1, 2, and 3 like this:
int a[3] = {1, 2, 3};
Representing Arrays in Memory
To represent an array in memory, we need to know how the elements of the array are stored
...
Each element of the array takes up space in memory, depending on its data type
...
Overall, understanding memory and arrays is crucial to programming, as they are fundamental building bl
ocks of many programs and applications
...
All the elements in an array are store
d in consecutive/continuous locations with the index starting at zero
...
One important point to note is that arrays are fixed-size
...
Accessing Array Elements
The index of the array starts at zero (although it can start at one in some cases)
...
To access an element, use th
e formula: base address + (i * size of data type)
...
Dynamic Allocation
The drawback of arrays is that the size needs to be specified at compile time, which may not always be p
ossible
...
If we allocate more space than neede
d, there will be unused memory
...
To dynamically allocate memory, we use functions such as ’malloc’ and ’calloc’
...
Error Handling
Unfortunately, there were some errors in the original text, making it difficult to understand
...
If you encounter any errors, please let me know
...
In the next video, we will discuss how to initialize an array at compile time and how to store data in the ar
ray at runtime
...
Additionally, we
will examine memory management and show how to use it to test our own code
...
In the next video,
we will cover how to insert data into arrays, traverse arrays, and work with 2D arrays
...
Arrays can have drawbacks, such as requiring elements of the same data type and not knowing the index
value
...
Title: Arrays in Data Structure | Declaration, Initialization, Memory representation
Description: Arrays in Data Structure | Declaration, Initialization, Memory representation Jenny's Lectures CS IT Understanding Memory and Arrays in Programming
Description: Arrays in Data Structure | Declaration, Initialization, Memory representation Jenny's Lectures CS IT Understanding Memory and Arrays in Programming