Multidimensional Arrays - PowerPoint PPT Presentation

1 / 7
About This Presentation
Title:

Multidimensional Arrays

Description:

Leftmost subscript varies most slowly known as row major order ... if (dptr==0)... Dynamic arrays (2) int y; cin y; int * ptr; // a ptr to an array of int's ... – PowerPoint PPT presentation

Number of Views:39
Avg rating:3.0/5.0
Slides: 8
Provided by: djfor
Category:

less

Transcript and Presenter's Notes

Title: Multidimensional Arrays


1
Multidimensional Arrays
2
Syntax
  • Type name d1d2d3 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 int5 // note constant size
  • if (dptrNULL) is better than if (dptr0)

5
Dynamic arrays (2)
  • int y
  • cingtgty
  • int ptr // a ptr to an array of int's
  • ptr new inty // 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 array0)
  • delete ptr // deletes the whole array

7
Strings
  • C-style strings (array of char)
  • char x xnew char n
  • Or
  • Using namespace std
  • include ltcstringgt
  • C style (true) strings
  • include ltstring.hgt
  • or
  • using namespace std
  • include ltstringgt
Write a Comment
User Comments (0)
About PowerShow.com