473,386 Members | 2,050 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,386 software developers and data experts.

how to dinamically allocate memory for two dimensional array?

Let's consider one dimensional array, which is defined like below:
int N=200;
int *tab=new int[N];
// do something with tab
delete tab;

I'd like to know why can I do the same for two dimensional array.
Please help me.
greetings, Pawel

Oct 29 '06 #1
4 3238
Pawel_Iks wrote:
Let's consider one dimensional array, which is defined like below:
int N=200;
int *tab=new int[N];
// do something with tab
delete tab;
It should be delete[] tab;
I'd like to know why can I do the same for two dimensional array.
int **ptr= new int*[N];
for(int i=0; i<N;++i)
ptr[i]=new int[N];

for(int i=0; i<N;++i)
delete[] ptr[i];
delete[] ptr;

Oct 29 '06 #2
"Pawel_Iks" <pa************@gmail.comwrote:
Let's consider one dimensional array, which is defined like below:
int N=200;
int *tab=new int[N];
// do something with tab
delete tab;

I'd like to know why can I do the same for two dimensional array.
Please help me.
Use the Matrix class in the FAQ.
http://www.parashift.com/c++-faq-lit...html#faq-13.10

--
To send me email, put "sheltie" in the subject.
Oct 29 '06 #3
Pawel_Iks wrote:
Let's consider one dimensional array, which is defined like below:
int N=200;
int *tab=new int[N];
// do something with tab
delete tab;
That should read:
delete [] tab;
I'd like to know why can I do the same for two dimensional array.
int n=200, m=100;
int *tab=new int[n*m];
// do something with tab
delete []tab;

But I wonder: why don't you use std::vector?

--
WW aka Attila
:::
A core dump is your computer's way of saying "Here's what's on my mind,
what's on yours?"
Oct 29 '06 #4
Thanks for everyone for help ...

Oct 29 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: M. Moennigmann | last post by:
Dear all: I would like to write a function that opens a file, reads and stores data into an 2d array, and passes that array back to the caller (=main). The size of the array is not known before...
4
by: marora | last post by:
I have created class definition which contains a charater pointer as one of it's data memeber. The objective is to read some data from a file, and assign it to a data member; Size of data is...
32
by: Mateo | last post by:
I have char *array and it is dinamically alocated.... When I pass it to other function, I need to determine size of this array.... Problem: sizeof operator does not work with dinamically alocated...
2
by: xhunga | last post by:
I have try a new version of my work. I have put the sizes of the matrix into the matrix. A = number of rows A = number of columns The first element of the matrix is A instead of A. You...
3
by: valerio | last post by:
Hello all I would like to dinamically allocate an array of array of structures. To explain this: struct file{ char* fileName,int inode) myfiles; struct file{ char* fileName,int inode) mydirs; ...
0
by: jmbn2k | last post by:
Hii Can anyone pls teme...how to allocate memory using malloc in a 3 D dimensional array........
8
by: per9000 | last post by:
Hi all, I have a two-dimensional array of data, f.x int's. We can imagine that the array is "really large". Now I want the data in it and store this in a one-dimensional array. The obvious...
1
by: trevor.farchild | last post by:
Hi, long time reader, first time poster I have an application that will be doing this 5 times a second: Get a bunch of data from a NetworkStream and convert it into a Bitmap Therefore, the...
11
by: Bryan Parkoff | last post by:
I want to know how much static memory is limited before execution program starts. I would write a large array. The large array has 65,536 elements. The data size is double word. The static...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.