-
What's wrong with this?
Hi,
Getting to grips with new operator.
What is wrong with the following code:
Code:
#include <iostream>
using namespace std;
void main()
{
x = new double[200];
cout << "x has size " << sizeof(x) << " and has value of %f" << x << endl;
}
Cheers
-
still need to declare a variable
Code:
double *x = new double[ 200 ];
no data type sets x to an int/undefined?? and sizeof(x) is returning 4 most probably ( 32 bits ) or 8 for 64-bit OS
-
Not an int. 'x' is undefined, so speculating the value of sizeof is pointless.
-
Don't forget to
delete [] x;
afterwards.
Also, main should return int.
You might also want to check up smart pointers.