Thread: about new

  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    25

    about new

    hello i cannot understand whats the benefit of saying that
    Code:
     int x=new int
    rather saying
    Code:
     int x;
    i know that new allocates memmory but please tell me the different of the above codes

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    The first is a compile error.
    Regardless, if you really meant a pointer, then the difference is that

    - You aren't limited to stack space (~1 MB usually).
    - The allocated storage won't be reclaimed as the function ends (extended lifetime; but comes with the disadvantage that you have to manually deallocate that).
    - You can dynamically specify size (you can only specify the amount of storage to reserve on the stack with something that is known at compile time).
    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.

Popular pages Recent additions subscribe to a feed