Hello,
i am little confused while i use delete operator. I am posting my code :-
In the above code i am confused as to whether i should use delete []p or i should use only p??None of them gives any syntactical error but i am confused i feel i should be delete []p but in Balagurusamy's book its given delete p.Code:#include"iostream.h" #include"string.h" class str { char *p; public: str(char *t) { p=new char[strlen(t)+1]; strcpy(p,t); } ~str() { delete []p; } void putdata() { cout<<p; } }; int main(void) { str t("Hello World"); t.putdata(); cin.ignore(); cin.get(); return 0; }
Also please try to explain in a clear cut manner like when i use double dimension array then what i should i write in delete???Please help me?