locked
Dynamic memory allocation in VC++ RRS feed

  • Question

  • Hello everyone,
    I have a simple question

    If make a char pointer and then create dynamically a char array of say 5 size....and then at the pressing a key i want to delete /release memory from specific index say index 2,and finally when my program ends it should delete/release memory from the remaining indexes...how is it going to be in vc++...

    in the following code i tried to do this but it gives error


    #include<iostream>
    #include<conio.h>
    using namespace std;
    void main() {
        char *text;
        text = new char[5];

        for(int i=0;i<5;i++)
            cin>>text[i];

        getch();
            //deleting
        delete text[4];
        getch();
            //deleting rest of array
        delete[] text;
    }



    thanks
    Saturday, December 31, 2011 11:01 AM

Answers