What is a 2D array in C.
14.11 Two-dimensional dynamic arrays
In Section 12.9 you read that the area of application of pointers to pointers is, among other things, the dynamic creation of matrices. I don't want to torment you now and take the matrix calculation as a topic, I will just make simple memory reservations with rows and columns:
So to reserve memory for a two-dimensional array with any number of rows and columns, you first need space for the row. And for each of these lines, additional space is required for the column. When freeing the memory, this must be done in reverse order.
Here is the full listing:
Admittedly, the listing has it all. For some it might seem a bit opaque how ** matrix becomes matrix [line] [column]. The best thing to do is to just take a look at what happened when the following memory reservation was made:
As an example, we want to create a 4 × 3 matrix, i.e. four rows and three columns.
Figure 14.9 Reservation of memory for the row (first dimension)
Now that you've reserved memory for each row, the next step is to reserve memory for each column.
The final image from Figure 14.10 then results in the memory.
Figure 14.10 After reserving memory for the column
You will probably remember the demonstration of equivalent access to a memory object using a pointer and an array in Chapter 12, "Pointers". There are also some equivalent cases for pointers to pointers and the two-dimensional arrays. You can find them listed in Table 14.2.
|access to||Possibility Number 1||Possibility 2||Option 3|
1st row, 1st column
i. Row, 1st column
1st line, i. column
i. Row, j. column
How did you like the Openbook? We always look forward to your feedback. Please send us your feedback as an e-mail to [email protected]
- Are newspapers made from recycled paper
- What goes well with garlic
- Are redheads hot
- Issues Walmart hunting fishing licenses
- Is there a drug for hearing loss?
- How can I become a computer technician
- What are five Swedish words to know
- Why is the band called The Killlers
- What allows the FTC to impose fines?
- Who is Young Thug
- Earthlink is still in business
- What are your reviews of Pyrocrat Systems
- When did Led Zeppelin make it big?
- How do you defuse the disarming of C4
- What's your rating of Wikiwand
- How to add footnotes in PowerPoint
- Is football culturally Marxist
- Why was the Indus Waters Treaty signed
- What does Waliman mean in Islam
- How can you create a document online
- Is the UHP nitrogen pure nitrogen
- Hard work leads to hair loss
- What are the uses of HSP90 screening
- How is the new SAT
- What is the SAR of J8
- What is digital space
- Can I get free money legally
- Is the airplane mode necessary
- Has a visa ever been hacked
- What are access modifiers in Java EE
- How is cloning possible?
- Can a 67 number leave a voicemail
- Use the Amazon Echo Dot Tap
- What are the best bartending books