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 149 views
149 views asked May 13, 2021 by avibootz
1 answer 133 views
2 answers 253 views
2 answers 173 views
173 views asked May 5, 2017 by avibootz
1 answer 146 views
...