memory allocation using new

G

gopesh patel

Hello all,

I have written a simple function as follows:

void test(float &b)
{
b = 100;
}

int main()
{
float *a;
a = new float[2];
test(*a);
delete [] a;
}

Now I initialized the first element of array using b =100 inside
function test().
But I cant find how to initialize the second element of this array ?
Could someone help me with the syntax for that ?

Thanks a lot.
Gopesh
 
S

Stuart Golodetz

gopesh said:
Hello all,

I have written a simple function as follows:

void test(float &b)
{
b = 100;
}

int main()
{
float *a;
a = new float[2];
test(*a);
delete [] a;
}

Now I initialized the first element of array using b =100 inside
function test().
But I cant find how to initialize the second element of this array ?
Could someone help me with the syntax for that ?

Thanks a lot.
Gopesh

test(a[1]); // note that test(*a); is equivalent to test(a[0]);

Cheers,
Stu
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top