473,397 Members | 1,950 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

how to define a bidimensional dynamic array as a global variable?

Hello everybody,

i am asking about how to define a bidimensional dynamic array as a global variable to use as incoming variable in a function

Let us see , for example in a part of a programm my problem:

#include<iostream>
...
using namespace std;

float a[10][10];//in this place i wish define a bidimenional dynamic array agian: how to do it?
...
//follow the function

float suma(int k, float a[][10])
{
float s=0;
for (int i=1;i<k;i++)
for (int j =1;j<k;j++)
s=s+a[i][j];
return (s);
}

int main()
{
...
suma(k,a);
...
}

But instead defining an static bidimensional array a[10][10], to use after as an incoming variable in a function, i wish to define it as dynamic array(to work with a huge array, for example(a[500][500]) )

would you like to help me?
Bye .
Miguel.
Oct 21 '08 #1
1 6236
arnaudk
424 256MB
First of all, it's usually not a good idea to use global variables. Then, before you start using 2D dynamic arrays, you should understand 1D dynamic arrays; you can then implement a 2D array as an array of an array. If performance is a real issue then use a proper matrix class like the one provided in boost or blitz++ (C++) or GSL (C/C++), there are many others.

Also, if your problem is simply that you wish to work with large arrays then this has nothing to do with dynamic arrays. Just declare a large static array.
Oct 21 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

34
by: Dennis | last post by:
I would like to dynamically allocate in a sub a 2 dimensional Array float *myarray = new float ; of course I get an error. How do you allocate a 2D array using the New operator? I...
4
by: J.P. | last post by:
Hi, I need to create a variable out of nothing. From a database I extract an item with a certain id. With this id I want to create a new variable. For example: id = 36; "item"+id = new...
17
by: Davor | last post by:
How to define global variable in main()? I'm asking because I have an array in main, whose size is determined by input, so the definition has to be in main ( or in some other funcion ). And I need...
23
by: Russ Chinoy | last post by:
Hi, This may be a totally newbie question, but I'm stumped. If I have a function such as: function DoSomething(strVarName) { ..... }
24
by: Ken | last post by:
In C programming, I want to know in what situations we should use static memory allocation instead of dynamic memory allocation. My understanding is that static memory allocation like using array...
4
by: Anna | last post by:
Hi, I have the following MySQL table: inner_id data1 data2 data3 ->0 g sd ds 1 a n ...
5
by: suresh | last post by:
Hi, How to define a two dimensional array where each row is of type vector<map<string,int>>? My idea is, if "x" is such a variable, x is a vector where each cell of the vector is a...
1
by: Bryan Parkoff | last post by:
An object can be defined using a class. The class contains variables and functions. It has a pointer to bind variables and functions. If I want to create more than one object. The class can...
8
by: Santiago Romero | last post by:
Hi :) First of all, I must apologize for my poor english :) I'm starting with python and pygame and for testing (and learning) purposes I wrote an small "Map Editor" for a small game project...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.