answersLogoWhite

0

The new operator works for two dimensional arrays the same way it works for one dimensional arrays, which is also the way it works for scalar objects.

int *p = new int; /* allocate a scalar */

int *p = new int[10]; /* allocate 10 of them */

int *p = new int[10][20]; /* allocate 200 of them */

The only difference between the array case and the scalar case is how you delete.

delete p; /* the scalar case */

delete [] p; /* any array case - one, two, or any dimensions */

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

What is multidimensional arrays?

A two-dimensional array is the simplest multi-dimensional array and is implemented as a one-dimensional array where every element is itself a one-dimensional array. We can imagine a two-dimensional array as being a table of rows and columns where every row is an array in its own right. A three-dimensional array is simply a one-dimensional array of two-dimensional arrays, which can be imagined as being an array of tables. Extending the concept, a four-dimensional array is a table of tables. Multi-dimensional arrays may be jagged. That is, a two-dimensional array may have rows of unequal length. Unlike regular arrays, jagged arrays cannot be allocated in contiguous memory. Instead, we use the outer array (the first dimension) to store pointers to the inner arrays. An array of strings (character arrays) is an example of a two-dimensional jagged array.


Does Java support multidimensional arrays?

Yes, Java supports multidimensional Arrays.Syntax isint[ ][ ] aryNumbers = new int[x][y];x represents number of rowsy represents number of columns


Why fixed size array is not efficient?

It's not exactly true. Array with fixes size are efficient, but do not work well when you have to resize your array. This actually is the answer for your question. Fixed size arrays are not efficient if you have to change the size. Also you cannot destroy them and release memory used to save the array (for that you have to use operator new).


Did Cary Grant work as an elevator operator in the flatiron building in New York?

yes


Difference between new operator and operator new?

new operator allows to allocate a memory from the heap..... so a new instance of a class is created.......... but operator new is used to overload the (new) operator........ juast like overloading of other operators


An array of array can be created in java?

Yes. int[][] as; // this will define an array of arrays of integers Multidimensional arrays, remember, are simply arrays of arrays. So a two-dimensional array of type int is really an object of type int array (int []), with each element in that array holding a reference to another int array. The second dimension holds the actual int primitives. The following code declares and constructs a two-dimensional array of type int: int[][] myArray = new int[3][]; Notice that only the first brackets are given a size. That's acceptable in Java, since the JVM needs to know only the size of the object assigned to the variable myArray.


How can two single dimensional array values be stored in a third single dimensional array?

You need to create a new array with enough elements to cater for both arrays. Thus if the first array has 10 elements and the second has 5, you must create a 15 element array to store both. You then copy elements from the first array into the third and immediately follow with the elements from the second. Note that the first two arrays must be of the same type. You cannot combine an array of numeric values with an array of strings, for instance.


What happen when a java keyword new is used in an application?

When the new operator is used, a new object is created, based on the specified class.When the new operator is used, a new object is created, based on the specified class.When the new operator is used, a new object is created, based on the specified class.When the new operator is used, a new object is created, based on the specified class.


What are the release dates for The New Operator - 1911?

The New Operator - 1911 was released on: USA: 24 July 1911


What is the use of new operator?

A new operater is used to allocating a memory space for a particular object.


Array as primitive data members in c plus plus program?

C-style arrays can be used as data members, both as fixed-size arrays or as dynamic arrays. The following examples demonstrate how they could be used as one-dimensional data members. class a { private: int b[10] {0}; // in-class initialisation (all elements zero). public: int& operator[] (unsigned index) { if (index>=10) throw std::range_error(); return b[index]; } }; class c { public: c (unsigned sz=10): size(sz), p (size?new int[size]:nullptr) { memset (p, 0, size); } c (const s& _s): size(_s.size), p (size?new int[size]:nullptr) { if (size) memcpy (p, _s.p, size); } c (s&& _s): size(_s.size), p (_s.p) { _s.p=nullptr; } // swap resources c& operator= (const s& _s) { if (p) delete [] p; size = _s.size; p = (size?new int[size]:nullptr); if (size) memcpy (p, _s.p, size); } c& operator= (s&& _s) { size = _s.size; p = _s.p; _s.p=nullptr; } // swap resources ~c() { if (p) delete [] p; } int& operator[] (unsigned index) { if (index>=size) throw std::range_error(); return p[index]; } private: unsigned size {0}; int* p {nullptr}; }; A much simpler approach would be to use std::array<int> and std::vector<int> instead of primitive C-style arrays.


How much does McDonald's pay if you are new?

It all depends on who owns the McDonalds in question (owner operator or corporation) it is their discretion, and is usually based on location and local competition. I work for an owner operator in Texas who starts crew at 7.