[cs13001] Pointer Inquiry

Mikhail Nesterenko mikhail at cs.kent.edu
Thu Apr 10 09:20:32 EDT 2014


> The code I'm looking at is as follows:
> 
> int *ptr1,*ptr2 = new int;
> ptr1=ptr2;
> ptr2 = new int;
> 
> My question is, would this be a memory leak?  ptr2 has a memory location
> then ptr1 is assigned to that location.  Then, ptr2 is set to a new memory
> location on line 3.  Since nothing is being reassigned the dynamic variable
> is not lost so it should not be a memory leak, right?

No, this is not a memory leak: when when "ptr2" is reassigned to new
memory address, "ptr1" remains pointing to the first memory
address. Thus both memory locations are accessible to the program.

> 
> Also, in class I noticed you had email notifications when you logged into
> vega, how did you go about setting that up?

I read my mail, including this one, on my Ubuntu (another flavor of
Unix) server "vega". I believe it saves me time since the interface is
purely command-line and hotkey based. Another advantage is that
viruses cannot come through email since it is received on Unix. 

I have set up an e-mail server (the technical term is mail transfer
agent) program called "sendmail".  My mail reader (email client, mail
user agent) is "mutt". The first step is not really necessary but adds
flexibility to mail processing.

Thanks,
--
Mikhail


More information about the cs13001 mailing list