100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.6 TrustPilot
logo-home
Summary

Summary ARRAYS IN DATA STRUCTURE

Rating
-
Sold
-
Pages
2
Uploaded on
08-07-2024
Written in
2023/2024

Declaration and Initialization of Arrays Arrays are used to store multiple items of the same data type. In C, arrays can be declared as follows: data_type array_name[array_size]; Here, data_type is the type of data that the array will store, array_name is the name of the array, and array_size is the number of elements that the array can hold. For example, the following code declares an array numbers that can hold 5 integers: int numbers[5]; Initialization of Arrays Arrays can be initialized using the following syntax: data_type array_name[array_size] = {value1, value2, ..., valueN}; Here, value1 to valueN are the initial values for the elements of the array. The number of values must be less than or equal to array_size. If you don't specify any values, all the elements of the array will be initialized to 0. For example, the following code declares and initializes an array numbers with the values 1, 2, 3, 4, and 5: int numbers[5] = {1, 2, 3, 4, 5}; Multi-dimensional Arrays Arrays can also be multi-dimensional, i.e., an array of arrays. A two-dimensional array can be declared as follows: data_type array_name[x][y]; Here, x and y are the number of rows and columns of the array, respectively. Multi-dimensional arrays can be initialized similarly to one-dimensional arrays, by specifying the values for each element. For example, the following code declares and initializes a 2x2 array matrix: int matrix[2][2] = {{1, 2}, {3, 4}}; Memory Representation of Arrays Arrays are stored in contiguous memory locations. This means that the elements of an array are stored in adjacent memory locations, which allows for efficient access and traversal of the array. The starting address of the array is the address of its first element, and the address of each subsequent element can be calculated by adding the size of the data type to the address of the previous element. For example, consider the following 1-dimensional array: int numbers[3] = {1, 2, 3}; The memory representation of this array would look like the following: | Address | Value | | --- | --- | | 1000 | 1 | | 1004 | 2 | | 1008 | 3 | The starting address of the array is 1000, and each integer is stored in 4 bytes of memory. The second element has an offset of 4 bytes (the size of an integer) from the first element, and the third element has an offset of 8 bytes. Note that this description is a simplification, as the actual memory address and layout may vary depending on the system and compiler. The important takeaway is that the elements of an array are stored in contiguous memory locations, which allows for efficient array traversal and operations.

Show more Read less
Institution
University Of The People
Course
ARRAYS IN DATA STRUCTURE (CSE)








Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
University Of The People
Course
ARRAYS IN DATA STRUCTURE (CSE)

Document information

Uploaded on
July 8, 2024
Number of pages
2
Written in
2023/2024
Type
SUMMARY

Subjects

$9.49
Get access to the full document:

100% satisfaction guarantee
Immediately available after payment
Both online and in PDF
No strings attached

Get to know the seller
Seller avatar
gururagav

Get to know the seller

Seller avatar
gururagav (self)
View profile
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
0
Documents
1
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Trending documents

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions