473,382 Members | 1,238 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,382 software developers and data experts.

Dynamic memory allocation

ifstream& operator>>(ifstream & input , Poly & a)
{


char *pol;
pol=new char[];
if(input==cin)
cout<<" Please Enter the Polynomial in a manner +1x^2-1x^1+10x^0 "<<"\n";
input>>pol;///////inputing a polynomial as a string
a.setPoly(pol);


return input;
}



Poly& Poly::setPoly(char *pol)////////////pointer to a pointer pol of string
{
int size=strlen(*pol);
cout<<*pol;

double *temp1=new double[degree+1],*temp=new double[degree+1],*deg=new double[degree+1];
long i=0,j=0,k=0,count=1,count1=0,count2=0,count3=0,cnt =1,power=0,pow=0,p=1,pp=1;

for( i=0 ; i<size ; i++)
{
if((int)pol[i]==43)
{
count1=0;
..............continue......

i want to ask that how should i pass a dynamically created string in a setPoly...........through pointer to a pointer or simple pointer or array ????
Nov 18 '08 #1
1 933
weaknessforcats
9,208 Expert Mod 8TB
It doesn't matter. Theya re both passed the same way.

When you pass an array to a function, all you pass is the address of element 0.

Expand|Select|Wrap|Line Numbers
  1. int array[10];
  2. int* darray = new int[10];
  3.  
darray is a pointer to an int. Specifically, it is the address of darray[0].

Likewise, array is the address of array[0].

Both darray[0] and array[0] are int. So darray and array are addresses of int. So array and darray are int*.

You pass these arrays to a function that has an int* argument. You will also need a second argument for the number of element in the array. Again, this is due to only the address of the array being passed. Unless you have a number of elements argument, there is no way the function can determine the number of elements.

Read this: http://bytes.com/forum/thread772412.html.
Nov 18 '08 #2

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

Similar topics

6
by: chris | last post by:
Hi all, I need to know, what is the difference between dynamic memory allocation, and stack allocation ? 1. If I have a class named DestinationAddress, when should I use dynamic memory...
11
by: toton | last post by:
Hi, I have little confusion about static memory allocation & dynamic allocation for a cluss member. I have class like class Bar{ public: explicit Bar(){ cout<<"bar default"<<endl; }
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...
1
by: Peterwkc | last post by:
Hello all expert, i have two program which make me desperate bu after i have noticed the forum, my future is become brightness back. By the way, my problem is like this i the first program was...
14
by: vivek | last post by:
i have some doubts on dynamic memory allocation and stacks and heaps where is the dynamic memory allocation used? in function calls there are some counters like "i" in the below function. Is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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
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?

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.