How to check if pointer is NULL in C

1 Answer

0 votes
#include <stdio.h>
#include <stdlib.h>

int main() {
    char *p = (char*) malloc(15 * sizeof(char));

    if (p == NULL) {
        printf("malloc error");
        return 1;
    }
    
    printf("malloc ok");
    free(p);
    
    return 0;
}






/*
run:

malloc ok

*/

 



answered May 13, 2021 by avibootz

Related questions

1 answer 226 views
226 views asked May 13, 2021 by avibootz
1 answer 216 views
2 answers 371 views
2 answers 292 views
292 views asked May 5, 2017 by avibootz
1 answer 226 views
...