Looking at this cplusplus.com time example, got me thinking more about pointers. The code has no delete
(and no new
).
Warning: I generally try to avoid pointers as much as possible, so I am definitely not proficient.
I've cut a lot of the code from the example below so as to focus on my question:
/* time example */
#include <stdio.h> /* printf */
#include <time.h> /* time_t, struct tm, difftime, time, mktime */
int main ()
{
time_t timer;
time(&timer); /* get current time; same as: timer = time(NULL) */
return 0;
}
Should I delete timer at the end of this, or is this just pointing to a system resource? My understanding is that whenever I use new
, I should use delete
. Is it right to think that as I am not using new
, I don't need delete
.
This stack question seems to be what I am looking for and explains I don't need delete
(which matches the example code on the website) as I am not doing a new
; however, I am not sure the functions I am using are not calling a new
somewhere (as I find it very hard to read the source). How do I know? Do I need to know?
I really hate working with this old time code and can't wait for the upcoming C++20 chrono
update, but this is too far away for my project.