I read about dynamic memory allocation in C using this reference.
That document Say's :
realloc() should only be used for dynamically allocated memory. If the memory is not dynamically allocated, then behavior is undefined.
If we use realloc() something like this:
int main()
{
    int *ptr;
    int *ptr_new = (int *)realloc(ptr, sizeof(int));
    return 0;
}
According to that reference, this program is undefined because pointer ptr not allocated dynamically.
But, If I use something like:
int main()
{
    int *ptr = NULL;
    int *ptr_new = (int *)realloc(ptr, sizeof(int));
    return 0;
}
Is it also undefined behavior according to that reference?
I thing second case does not invoked undefined behaviour. Am I right?
 
     
     
     
    