In C++, assuming no optimization, do the following two programs end up with the same memory allocation machine code?
int main()
{
int i;
int *p;
No, without optimization ...
int main()
{
int i;
int *p;
}
does almost nothing - just a couple of instructions to adjust the stack pointer, but
int main()
{
int *p = new int;
delete p;
}
allocates a block of memory on heap and then frees it, that's a whole lot of work (I'm serious here - heap allocation is not a trivial operation).