Thread: What's wrong with this?

  1. #1
    Registered User
    Join Date
    Nov 2006

    Smile What's wrong with this?


    Getting to grips with new operator.

    What is wrong with the following 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;

  2. #2
    Registered User
    Join Date
    Mar 2011
    still need to declare a variable
    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

  3. #3
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    United States
    Not an int. 'x' is undefined, so speculating the value of sizeof is pointless.

  4. #4
    Join Date
    Oct 2007
    Inside my computer
    Don't forget to
    delete [] x;

    Also, main should return int.
    You might also want to check up smart pointers.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. wrong wrong with my xor function?
    By Anddos in forum C++ Programming
    Replies: 5
    Last Post: 04-26-2009, 01:38 PM
  2. whats wrong with this? no errors but wrong result
    By InvariantLoop in forum C Programming
    Replies: 6
    Last Post: 01-28-2005, 12:48 AM
  3. Replies: 9
    Last Post: 07-15-2004, 03:30 PM
  4. What's wrong
    By money? in forum C Programming
    Replies: 3
    Last Post: 06-14-2003, 07:13 PM
  5. What am I doing wrong?!
    By NebulousMenace in forum C++ Programming
    Replies: 4
    Last Post: 02-05-2003, 11:26 AM