Why, when setting up the buffer below, do you not need to use malloc to set aside memory for it? My code works fine, I just want to understand this a little better. Thanks, in advance, for the help.

int16_t buffer;
    while (fread(&buffer, sizeof(int16_t), 1, input))
        buffer = buffer * factor;
        fwrite(&buffer, sizeof(int16_t), 1, output);

2 Answers 2


You are declaring int16_t buffer;. That allocates space on the stack for one 16 bit integer.


You can also create 16 bits on heap and use it this way

int16_t *buff = malloc(sizeof(int16_t));

while(fread(buff, sizeof(int16_t), 1, input))
    *buff = (*buff) * factor;
    fwrite(buff, sizeof(int16_t), 1, output);

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .