Skip to content

Commit 6438b28

Browse files
authored
Update Array.md
1 parent c487dfe commit 6438b28

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

Array.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ int main()
186186
int index;
187187

188188
// iterate the array elements using loop if any element matches the key, store the index
189-
for (i = 0; i < n-1; i++)
189+
for (i = 0; i < n; i++)
190190
{
191191
if (array[i] == x)
192192
{
@@ -200,3 +200,44 @@ int main()
200200

201201
}
202202
```
203+
204+
### Update
205+
Update operation refers to updating an existing element from the array at a given index.
206+
207+
```c
208+
#include<stdio.h>
209+
int main()
210+
{
211+
int array[5] = { 2, 6, 8, 3, 9};
212+
213+
// initial size of array
214+
int n = 5;
215+
int i = 0;
216+
217+
// element to be switched
218+
int x = 6;
219+
220+
// element with which to be switched
221+
int y = 4;
222+
int index;
223+
224+
// iterate the array elements using loop if any element matches the key, store the index
225+
for (i = 0; i < n-1; i++)
226+
{
227+
if (array[i] == x)
228+
{
229+
array[i] = y;
230+
break;
231+
}
232+
}
233+
234+
// print the index of element
235+
for (i = 0; i < n; i++)
236+
printf("%d ",array[i]);
237+
}
238+
```
239+
240+
## Conclusion
241+
Arrays store multiple elements of the same type with the same name.You can randomly access elements in the array using an index number.Array memory is predefined, so there is no extra memory loss.Arrays avoid memory overflow.2D arrays can efficiently represent the tabular data
242+
243+
The number of elements in an array should be predefinedAn array is static. It cannot alter its size after declaration.Insertion and deletion operation in an array is quite tricky as the array stores elements in continuous form.Allocating excess memory than required may lead to memory wastage.

0 commit comments

Comments
 (0)