Chapter7

# Chapter7 - Engineering Problem Solving with C+,...

This preview shows pages 1–3. Sign up to view the full content.

Engineering Problem Solving with C++, second edition, J. Ingber 1 Engineering Problem Solving with C++, Etter/Ingber Chapter 7: Two-Dimensional Arrays and Matrices Prof. Xin Wang (xwang@ece.sunysb.edu) Office: 235 Light Engineering building Class time: TuTh 3 :50 pm 5:10 pm Two Dimensional Arrays ± Declaration and Initialization ± Computation and Output ± Function Arguments Engineering Problem Solving with C++, second edition, J. Ingber 2 DECLARATION AND INITIALIZATION Engineering Problem Solving with C++, second edition, J. Ingber 3 Declaration and Initialization ± The declaration of a two-dimensional array requires a row size and a column size . ± A consecutive block of ( row size )(* column size ) memory locations are allocated. ± The name of the array holds the address of the first byte of memory. Engineering Problem Solving with C++, second edition, J. Ingber 4

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
Engineering Problem Solving with C++, second edition, J. Ingber 5 Example: //Declaration int data[2][3]; Memory Snapshot ? ? ? ? ? ? data Engineering Problem Solving with C++, second edition, J. Ingber 6 Example: ??? row 0 row 1 //Declaration int data[2][3]; col 0 col 1 col 2 row/column form: Engineering Problem Solving with C++, second edition, J. Ingber 7 Example: //Declaration and Initialization double t[2][2] = { {0.1,0.2}{1.1, 1.2} }; 0.1 0.2 1.1 1.2 Memory Snapshot row 1 row 0 col 1 col 0 0.1 0.2 1.1 1.2 t Assigning data to 2-D Arrays ± Initialization: char table[2][3]{ {'a','g','k'}{'c', 'm', 'h'}}; ± Assignment using nested for loops for (int i=0; i<2; i++) // for every row for (int j=0; j<3; j++) // for every col cin >> table[i][j]; 'h' 'm' 'c' 'k' 'g' 'a'
This is the end of the preview. Sign up to access the rest of the document.

## Chapter7 - Engineering Problem Solving with C+,...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online