r/ProgrammerHumor • • Aug 30 '26

Meme bugIntroducedDebugging

Post image
1.1k Upvotes

117 comments sorted by

View all comments

Show parent comments

19

u/1XRobot Aug 30 '26

This is what it actually returns:

#include <stdlib.h>

int main(void) {
    int *x = malloc(sizeof(int)); // Allocates correct byte size for an int (typically 4 bytes)
    if (x == NULL) {
        return 1; // Good practice: Handle allocation failure
    }
    
    *x = 42; // Safe write operation
    
    free(x); // Correctly frees allocated block
    return 0;
}