Search code examples
cmemoryconsumption

Memory Consumption?


I have a piece of code where

for ( ; ; )
{

  char *buf;

  /* Some code */
}

The question here will the code allocate memory every time when it cycles through the loop . I mean atleast 4 bytes will be reserved for the pointer when it cycles .


Solution

  • Space for the pointer will be allocated on the stack, but it will be popped off at the end of every iteration, so you don't need to worry about it.