Tuesday, June 23, 2015

malloc returns NULL

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

int main()
{
    char *ptr = NULL;
    ptr = malloc(SIZE_MAX);
    if (ptr == NULL)
        printf("memory allocation failed\n");
    else
        printf("memory allocation success\n");
}

Where SIZE_MAX is defines as

/* Limit of `size_t' type.  */
# if __WORDSIZE == 64
#  define SIZE_MAX      (18446744073709551615UL)
# else
#  define SIZE_MAX      (4294967295U)
# endif
 

No comments:

Post a Comment