2_D array_C++

2_D array_C++ - Declaring a 2-dimensional array: char...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Declaring a 2-dimensional array: char TicTacToeBoard[3][3] = { {'x', 'x', 'o'}, {'o', 'o', 'x'}, {'x', 'o', ' '} }; // Char type board 3x3 int i, j, Matrix[30][10]; // declares an int array of 30 rows and 10 columns. for(i = 0; i < 5; i++) for(j = 0; j < 7; j++) Matrix[i][j] = 0; Two-Dimensional Arrays as Function Parameters : void ReadScores(int labScores [MAX_STUDENTS][MAX_LABS], //OUT: student labs int& numStudents, //OUT: actual # of students int& numLabs, //OUT: actual # of labs ifstream& fin) //IN: input file stream { //local variables int student, lab; //index for the student and lab being processed //first read the number of students and labs stored in the file. fin >> numStudents >> numLabs; //Outer loop controls which student (row) is being read for (student = 0; student < numStudents; student++) //Inner loop controls which lab (column) is being read for (lab = 0; lab < numLabs; lab++) fin >> labS [student][lab]; } As with one-dimensional arrays, a two-dimensional array is automatically passed
Background image of page 1

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

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/04/2011 for the course CSCI 101 taught by Professor Ghyam during the Spring '08 term at USC.

Page1 / 3

2_D array_C++ - Declaring a 2-dimensional array: char...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online