Total members 11894 |It is currently Fri Nov 22, 2024 8:48 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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 :
cpp 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





Author:
Proficient
User avatar Posts: 280
Have thanks: 1 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.

_________________
Please recommend my post if you found it helpful


Author:
Proficient
User avatar Posts: 228
Have thanks: 0 time
Post new topic Reply to topic  [ 2 posts ] 

  Related Posts  to : dynamic array as global variables
 Accessing Global Variables with the global Statement     -  
 Dynamic Array Allocation     -  
 Dynamic Domain Name System (Dynamic DNS )     -  
 Local variables vs Instance variables     -  
 global statement in php     -  
 how to call a global variable?     -  
 How do you 301 redirect a dynamic URL?     -  
 make Dynamic Bar Chart by php     -  
 How to generate dynamic 3d pie chart in php???     -  
 DYNAMIC DATES IN MYSQL     -  



Topic Tags

C++ Arrays, C++ Basics
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com