Consider:
char *p=NULL;
free(p) // or
delete p;
What will happen if I use free
and delete
on p
?
Nothing will happen if you call free with a NULL parameter, or delete with an NULL operand. Both are defined to accept NULL and perform no action.
There are any number of thing you can change in C++ code which can affect how fast it runs. Often the most useful (in approximate order) are:
Having said that, divideandconquer is absolutely right - you can't effectively speed your program up unless you know what it spends its time doing. Sometimes this can be guessed correctly when you know how the code works, other times it's very surprising. So it's best to profile. Even if you can't profile the code to see exactly where the time is spent, if you measure what effect your changes have you can often figure it out eventually.