Total members 10249 | Gratitudes |It is currently Thu May 17, 2012 7:57 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 2 posts ] 
Author Question
 Question subject: dynamic array as global variables
PostPosted: Sat Nov 08, 2008 3:25 pm 
Offline
Proficient
User avatar

Joined: Sun Oct 19, 2008 3:47 pm
Posts: 281
Has thanked: 0 time
Have thanks: 1 time

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


Program :
Code:
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



TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: dynamic array as global variables
PostPosted: Sat Nov 08, 2008 3:27 pm 
Offline
Proficient
User avatar

Joined: Sun Oct 19, 2008 3:53 pm
Posts: 229
Has thanked: 0 time
Have thanks: 0 time
they can be defined before headers, before using namespace, and it's the same
for all variables.
Something you might try is:
Code:
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.


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 2 posts ] 
Quick reply


  

 Similar topics
 search for string in a cell array
 Shuffle Array
 check array contains a value using javascript
 Array size to zero
 Dynamic Frame-sets with java script protocols
 array in oracle database
 How to write C++ code that defines array of size 24 then;
 access element in array C++
 Average of an array. Please help
 need some help with array comparing program (solved)

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 2 guests



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team