Hi,
Getting to grips with new operator.
What is wrong with the following code:
CheersCode:#include <iostream> using namespace std; void main() { x = new double[200]; cout << "x has size " << sizeof(x) << " and has value of %f" << x << endl; }
This is a discussion on What's wrong with this? within the C++ Programming forums, part of the General Programming Boards category; Hi, Getting to grips with new operator. What is wrong with the following code: Code: #include <iostream> using namespace std; ...
Hi,
Getting to grips with new operator.
What is wrong with the following code:
CheersCode:#include <iostream> using namespace std; void main() { x = new double[200]; cout << "x has size " << sizeof(x) << " and has value of %f" << x << endl; }
still need to declare a variableno data type sets x to an int/undefined?? and sizeof(x) is returning 4 most probably ( 32 bits ) or 8 for 64-bit OSCode:double *x = new double[ 200 ];
Not an int. 'x' is undefined, so speculating the value of sizeof is pointless.
Originally Posted by phantomotap
Don't forget to
delete [] x;
afterwards.
Also, main should return int.
You might also want to check up smart pointers.
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^
Something you should read regarding void main(): Cprogramming.com FAQ > main() / void main() / int main() / int main(void) / int main(int argc, char *argv[]).