Gopi Krishna Komanduri wrote:
> Hi , I want to know 3 things.
4 things.
> 1)In C++ , when we try to delete a this pointer , what will happen? .
> I tried to do it . when we call delete , desctructor for that object
> is called and again control returns back to member function next line
> and finished fine.My assumption is like , the memory for this pointer
> is not allocated by user , so we can't delete this. am I correct ?
Well, you can call the delete operator on *this. It frees the memory
associated with the object - it doesn't "free" a function (you can't do
that anyway). So as long as you don't use any member variables for the
rest of the lifetime of the function, the program will still operate.
The real question is: Why would you ever want to do that? I've never
had a need to do so.
> 4) main() { printf("%d"); }; In the
> above , the output I am getting is garbage. But what I am thinking is
> as printf is a function and %d is one parameter and no other
> parameters , it will push only %d onto stack . so when it starts
> executing , it will pop only %d and it won't get any other value
> from stack to resolve that %d. So May I know how compiler is giving
> some garbage , with out stops printing?
Don't do that. You are referencing stuff on the stack that is outside
the valid range of your program. Undefined behavior is the result.
--
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197
*NEW* VerifyMyPC 2.5
Change tracking and management tool.
Reduce tech. support times from 2 hours to 5 minutes.
http://www.CubicleSoft.com/VerifyMyPC/