So I allocate new memory for a char, int, and string variable,
initialize each one, and output each to the screen. Afterwards,
I deallocate each of them and output them again to see if they
would output the previous values. The int and char values were
deleted properly but the string was not and I used the delete
variable for each three the same.
For example....before deleting each variable...
after deleting each variable...
*p = 25
ch = This is the char var
*str = This is the string var
*p = 4073560
ch = -
*str = This is the string var ///Why does only this one stay the same
using namespace std;
p = new int;
ch = new char;
str = new string;
*p = 25;
strcpy(ch, "This is the char var");
*str = "This is the string var";
Also, before deallocating any memory
, why does the char variable, ch
only output one letter without using the * operator as opposed to
outputting the whole sentence when using the * operator. That is
why I outputted the ch
variable on line 22 without the * operator.
Thanks for any response