![]() |
|
#1
|
||||
|
||||
Create 2D Array!hi
can we construct a 2Dimensional array with int (*a)[10]; ??????? thnx |
|
#2
|
|||
|
|||
Re: Create 2D Array!!!Quote:
In the first place, in C (and C++) there actually isn't any such thing as a 2-Dimensional array. We talk about such things, and there is notation for such things, but actually there are arrays (1-Dimensional). You can have an array of arrays and call it a 2-Dimensional array, (and we usually do). Your statement declares that a is a pointer to an array of 10 ints. If we want an array of arrays of 10 ints, then we could do something like the following CPP / C++ / C Code:
Output: Code:
Regards, Dave |
|
#3
|
||||
|
||||
Re: Create 2D Array!!!thnx..
wat is the diff in implementing a multi-dimensional array using int *a[10] and int (*a)[10] ??? |
|
#4
|
|||
|
|||
Re: Create 2D Array!!!Quote:
The following statement declares a to be an array of 10 pointers to int CPP / C++ / C Code:
a[0] is a pointer to int a[1] is a pointer to int . . . a[9] is a pointer to int You can access a particular integer in the array by a[i][j] where i is greater than or equal to zero and less than 10 and j is greater than or equal to zero and less than however many ints for which you allocate storage and assigned the memory to a[i] A 2-D array from this would involve allocating storage and assigning an address for each of the a[i]. You could consider that the array has 10 "rows," and each row can have as many ints as you allocate. In the previous example, you end up with an array that has as many "rows" as you want (the value of n in the program), and each row has 10 ints. So in the previous example a[0] is a pointer to an array of 10 ints a[1] is a pointer to an array of 10 ints. . . a[n-1] is a pointer to an array of 10 ints. You can access any integer by a[i][j] where i is greater than or equal to zero and less than n j is greater than or equal to zero and less than 10 Regards, Dave |
|
#5
|
||||
|
||||
Re: Create 2D Array!!!nice piece of info . .
thnx |
Recent GIDBlog
Toyota - 2008 August Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How Do I Create a Function that returns a usable array of pointers to structures? | UncleRic | C Programming Language | 2 | 03-Sep-2007 11:17 |
| How to sort in C++ alphabetically | wilen | C++ Forum | 5 | 20-Apr-2007 14:43 |
| Need help deleting the last element in the array | headphone69 | C++ Forum | 2 | 15-Mar-2006 19:31 |
| Pointer Usage in C++: Beginner to Advanced | varunhome | C++ Forum | 0 | 19-Aug-2005 09:25 |
| template comiling problems - need expert debugger! | crq | C++ Forum | 1 | 01-Feb-2005 21:26 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The