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.
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
binary, 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 represented as 101 in binary
...
For example, an array of characters 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 values 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 blocks of many programs and
applications
1
...
We have already covered
the fundamentals of arrays, including why they are needed, how to
declare them, and their memory representation in a previous post
...
The most important operations we will cover
are array traversal, insertion, deletion, sorting, and searching for a
particular key
...
We will also provide code for
array deletion
...
Additionally, arrays do not have any bounds checking property at
runtime, so it is the programmer's responsibility to check the
boundaries of the array in the program
...
The base address is 100, so 100 to 299 bytes should
be allocated to this array
...
The scanf function is used to take input from the user, and
the printf function is used to print something on the output screen
...
We use a for loop to
iterate over the array, and the value starts from 0 till the size minus one
(i++)
...
The user can insert data into the array, and the number of data
they want to insert is the size of the array
...
Inserting Data and Indexing
The user can insert data into an array by using the scanf function
...
The length of a single
element is the same as the number of bytes that will be inserted
...
The index for a value is a single number, and the number is not an error
...
Deletion and Sorting
In addition to insertion, we will also cover array deletion and sorting
...
Overall, arrays are an important data structure in computer science, and
understanding how to perform operations on arrays is essential for any
programmer
...
1
...
We will
use an example array of size 5 to explain the process of deleting data
from a specific position, beginning, and end of the array
...
First, we initialize an array of size 50 but ask the user for the number of
elements they want to insert
...
For
example, if they choose position 2 (index 1), we cannot leave that space
blank
...
We start a loop to shift the elements to the left, starting from the index
before the position chosen by the user until the second last index of the
array
...
If we want to print the
deleted data, we store it in a separate variable before shifting the
elements
...
int size = 5; int arr[size]; int pos, i;
item;
// ask user for position to delete
printf("Enter position to delete: ");
int
scanf("%d",
&pos);
// check if valid position
|| pos > size) {
printf("Invalid position");
else if (pos == size) {
position %d", pos);
shift elements
arr[i] = arr[i+1];
of array
if (pos <= 0
}
printf("No data at
} else {
// start loop to
for (i = pos-1; i < size-1; i++) {
}
size--; // decrease size
}
1
...
If you have discussed the relationship
between arrays and pointers I mean that 1d array and pointers you can
check out that video also in that I button
...
P can contain
address of an integer variable only so this is invalid right so here can we
write P is equal to CP contains address of some another integer variable
address off integer readable so can I write here a the name of theory
...
you fine it will print in unsigned integer some integer value so you
can print if you print in printf I guess you can
...
can write what a simply the name of the area or it will give what
the address of the first element first element is what a of 0 0 is what 100
only fine you can say that base address of this is 100
2
...
Memory manager will
allocate how many bytes 3 into 4 that is 2 any bytes fine so let us
suppose one complete block of 12 bytes has been allocated suppose
from 102 from hundred to this one one one this is free
...
Memory is not free the
memory manager can not allocate this free memory to another variable
but this programmer is not using that memory so this is what the
wastage of memory is there
...
The only difference is
this data items are not storing consecutive locations because this in
area these are stored in consecutive location continuous location
...