Download presentation
Presentation is loading. Please wait.
Published byCorey Neal Modified over 9 years ago
1
Multidimensional Arrays
2
Syntax Type name [d1][d2][d3] {init list}; int X [3] [4] [5]; Leftmost subscript varies most slowly – known as row major order
3
Arrays as arguments function X (int x, int y, int a [x] [y]) {... } Not valid in MANY C compilers New standard as of 1999 implemented ??? function X (int a[ ] [7]) {... } // valid highest dimension is still required
4
Dynamic arrays (1) Requires the use of the new operator Syntax: new Type [amount] int * ptr; // a ptr to an array of int's ptr= new int[5]; // note constant size if (dptr==NULL) … is better than if (dptr==0)…
5
Dynamic arrays (2) int y; cin>>y; int * ptr; // a ptr to an array of int's ptr= new int[y]; // note size determined at //run time BUT: the size of the array is still FIXED
6
Deleting storage Given the previous array: delete ptr; // deletes a SINGLE datum –the one memory loc that ptr refers to –Even if it's an array (only deletes array[0]) delete [ ] ptr; // deletes the whole array
7
Strings C-style strings (array of char) –char *x; x=new char [n] –Or Using namespace std; #include C++ style (true) strings #include –or using namespace std; #include
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.