they can be defined before headers, before using namespace, and it's the same
for all variables.
Something you might try is:
float* vals;
int main()
{
vals=new float[i][j];
}
And it is before your loop. you can't put code out side of a function like that.
Thanks,
_|_|_|_|_| _| _|_|_|_|
_| _|_|_| _| _|_|_|
_| _| _| _|_|_| _|
_| _| _| _| _|
_| _| _| _|_|_|_| _|_|_|
Visit TDS for quality software and website production
http://tysdomain.com
msn: [EMAIL PROTECTED]
aim: st8amnd2005
skype: st8amnd127
----- Original Message -----
From: Miguel Caro
To: [email protected]
Sent: Wednesday, October 08, 2008 7:01 PM
Subject: Re: [c-prog] dynamic array as global variables to use in a function
Hi Tyler(hi everybody)
well, maybe i did not explain very well.
i wish define a bidimensional dinamic array in this form as a global
variable
...
#define N 1000
#define J 1000
using name space std;
double ** a = new double [N+1]
for (int i=0;i<N+1;i++)
a[i] = new double[J+1]
...
int main()
{
...
...
}
in this part the programm shows an error. I think that before command main()
i cannot use
for (int i=0; i<N...)
In a few words, how can i define a bidimensional dinamic array as a global
variable)
is it true that global variables are defined after command using namespace
std and before main()?
Thanks all.
Miguel.
Tyler Littlefield wrote:
>
> I'm really confused what your asking. you want a global array--just define
> it outside the function, as you did.
>
> Thanks,
> _|_|_|_|_| _| _|_|_|_|
> _| _|_|_| _| _|_|_|
> _| _| _| _|_|_| _|
> _| _| _| _| _|
> _| _| _| _|_|_|_| _|_|_|
> Visit TDS for quality software and website production
> http://tysdomain.com
> msn: [EMAIL PROTECTED]
> aim: st8amnd2005
> skype: st8amnd127
> ----- Original Message -----
> From: Miguel Caro
> To: [email protected]
> Sent: Wednesday, October 08, 2008 6:15 PM
> Subject: [c-prog] dynamic array as global variables to use in a function
>
>
>
> Hello everybody,
>
> well i wish to ennounce two global variables to use after in a function.
> One variable i define as an unidimensional vector. I did it very well, i
> think so, the variable is called x[].
> But i wish to define a new global variable, as bidimensional dynamic
> array,
> is called a[][]. But i don't know how to define this dynamic array a[][]
> as
> global variable.
>
> I knwo how to define dynamica array(unidimensional or bidimensional)
> inside
> the main program or inside any function, but as a global variable?
>
> It is important to remark that i have defined in my program three or
> more
> functions whose one of incoming variables is a bidimeniosnal dynamic
> array.
>
> Next i post a part of program
> Any help it is important to me.
> Thank You all,
> Miguel.
>
> Program
> using namespace std;
> float a[16][16];//in this part i wish define the bidimensional dynamic
> array
>
> //i'm defining unidimensional dynamic array x
> const N=1000;
> float* x = new float[N];
> //first function using dynamic array x[]
>
> float suma3(float x[])
> {
> int j; float s=0.0;
> for (j=1;j<16;j++)
> s=s+x[j];
> return(s);
> }
> //second function i wish , for example here, usin a[][] as bidimensional
> dynamic array. how to do?
> float suma1(int i, float x[], float a[][16])
> {
> int l;
> float s=0;
> for (l=1;l<i;l++)
> {
> s=s+a[i][l]*x[l];
> }
> return(s);
> }///fin suma 1
>
> --
> View this message in context:
>
http://www.nabble.com/dynamic-array-as-global-variables-to-use-in-a-function-tp19813653p19813653.html
> Sent from the C-prog mailing list archive at Nabble.com.
>
> [Non-text portions of this message have been removed]
>
>
>
>
>
> __________ NOD32 3505 (20081008) Information __________
>
> This message was checked by NOD32 antivirus system.
> http://www.eset.com
>
>
> [Non-text portions of this message have been removed]
>
>
>
--
View this message in context:
http://www.nabble.com/dynamic-array-as-global-variables-to-use-in-a-function-tp19813653p19890466.html
Sent from the C-prog mailing list archive at Nabble.com.
__________ NOD32 3505 (20081008) Information __________
This message was checked by NOD32 antivirus system.
http://www.eset.com
[Non-text portions of this message have been removed]