Thread: C and C++ pointers

  1. #1
    Registered User
    Join Date
    May 2009

    C and C++ pointers

    Is there any difference btwn C and C++ pointers?Can someone explain to me the use of new and delete operators in C++?Thkx.

  2. #2
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Banks of the River Styx
    Not much difference. They are a variable that holds a memory address. It might be noted that changing the type of a pointer from a derived class to a base class in some cases may also change the value of the pointer (in the case of multiple base classes, for example) -- this is transparent to you as a programmer 99% of the time.

    new allocates memory. delete frees it. Example:
    std::string *s;
    s = new std::string();
    // use s
    delete s;
    s = new std::string[5]; // allocate an array of 5 strings.
    // use the array
    delete[] s; // You MUST pair delete[] with new[], and delete with new.
    new & delete handle the calling of constructors/destructors for classes.
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

Popular pages Recent additions subscribe to a feed