|
From: Daniel G. <sp...@ho...> - 2002-09-05 09:59:50
|
Quick guess, I think you need the for loop to create an array of pointers or
something. Your suggested method would only have one pointer, and then you'd
need to store the addresses of the arrays and/or their data.
Just a quick guess, could be well off.
>From: senem beken <sbe...@ya...>
>To: dev...@li...
>Subject: [Dev-C++] q3??
>Date: Thu, 5 Sep 2002 02:49:38 -0700 (PDT)
>
>
>
>
>include <iostream>
>#include <stdlib.h>
>
>int main()
>{
> int nrows,ncolumns;
> nrows=ncolumns=5;
> int **arr=new int*[nrows];
> for(int i=0;i<ncolumns;i++) //why do i have to use a for loop
> arr[i]=new int[ncolumns]; //to create a multiple subs array
> // dynamically??
> //why can't i use a code like:
> //int **arr=new int*[nrows];
> // *arr=new int[ncolumns]; ???
>
>
> for(int i=0;i<nrows;i++)
> for(int j=0;j<ncolumns;j++)
> arr[i][j]=0;
>
> for(int i=0;i<nrows;i++)
> for(int j=0;j<ncolumns;j++)
> cout<<arr[i][j]<<" ";
>
> cout<<sizeof(arr)/sizeof(int)<<endl; //and why does this part return
>1
> //instead of 25??
> cout<<nrows<<" "<<ncolumns<<endl;
> system("PAUSE");
> return 0;
>}
>
>
>
>---------------------------------
>Do You Yahoo!?
>Yahoo! Finance - Get real-time stock quotes
_________________________________________________________________
Join the worlds largest e-mail service with MSN Hotmail.
http://www.hotmail.com
|