473,386 Members | 1,908 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.

need for simple program of arrays

declare two dimensional array of type double using dynamic memory allocation then write code to delete this two dimensional array???
Oct 1 '06 #1
4 2880
m013690
23
declare two dimensional array of type double using dynamic memory allocation then write code to delete this two dimensional array???
double *dPtr[5] = new double[5];

delete[ ] dPtr;
Oct 1 '06 #2
D_C
293 100+
Expand|Select|Wrap|Line Numbers
  1.   int WIDTH;
  2.   int HEIGHT;
  3.  
  4.   cout << "Enter array width: ";
  5.   cin >> WIDTH;
  6.   cout << "Enter array height: ";
  7.   cin >> HEIGHT;
  8.  
  9.   char* array2D = (char*)malloc(WIDTH*HEIGHT*sizeof(char));
  10.   free(array2D);
Oct 2 '06 #3
i asked for a program which declares a two dimensional array of type double using dynamic memory allocation and then delete this array but im a begginer in c++ and i dont know how to completly write it ,i tried and thats it
#include<iostream>

using namespace std;

int main()
{


double *dPtr[5]= new double[5];


delete[] dPtr;
cout<<&dPtr[]<<" "<<endl;
return 0;
}
Oct 3 '06 #4
Banfa
9,065 Expert Mod 8TB
Please don't double post

Unfortunately you have chosen to use the non-working code from this thread instead of the working code. There is no such thing as an allocated 2D array, it's in your head.

However you can simulate this imaginary concept like this

Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     double *dPtr[5];
  8.     double *data = new double[25];
  9.  
  10.     dPtr[0] = data;
  11.     dPtr[1] = dPtr[0]+5;
  12.     dPtr[2] = dPtr[1]+5;
  13.     dPtr[3] = dPtr[2]+5;
  14.     dPtr[4] = dPtr[3]+5;
  15.  
  16.     delete data;
  17.  
  18. //    cout<<&dPtr[]<<" "<<endl;
  19.  
  20.     return 0;
  21. }
  22.  
I have commented out the cout line because it is not at all clear what you where trying to achieve with it (especially after the data has been deleted).
Oct 3 '06 #5

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

Similar topics

13
by: Roy Riddex | last post by:
2nd post of the day! I'm just learning about Arrays at College and have met a problem. I have 5 text boxes for number input, a command button to add the numbers to the array, and a command button...
31
by: da Vinci | last post by:
OK, this has got to be a simple one and yet I cannot find the answer in my textbook. How can I get a simple pause after an output line, that simply waits for any key to be pressed to move on? ...
1
by: John Smith | last post by:
I have a two dimentional char array. Before filling it using strtok(), I reset its elements to '\0' using two nested for loops. The code works as I hope it would but I wonder whether I really need...
8
by: hothead098 | last post by:
ASSIGNMENT (4) USING AND MANIPUPATING ARRAYS (Chapter 10 material) For this assignment you are to: 1) Create and manage arrays a) One of type integers (containing 10 elements). b) One of...
16
by: C++ Hell | last post by:
Hey everyone just designing a quiz for school and managed to write the code for the questions and answers thou i have to add scores and at the end an overall score does anyone have any idea what to...
4
by: learnfpga | last post by:
Here is a little code I wrote to add the numbers input by the user.....I was wondering if its possible to have the same functionality without using dynamic arrays.....just curious..... ...
23
by: vinod.bhavnani | last post by:
Hello all, I need desperate help Here is the problem: My problem today is with multidimensional arrays. Lets say i have an array A this is a 4 dimensional static array.
24
by: Michael | last post by:
Hi, I am trying to pass a function an array of strings, but I am having trouble getting the indexing to index the strings rather than the individual characters of one of the strings. I have...
9
by: lilchiko1286 | last post by:
I am taking an intro to C++ course in college. I was assigned a project that i must complete on MS Visual Studio in where I am supposed to prompt the user for a name and then a letter and output...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.