Checking if a pointer is allocated memory or not

前端 未结 18 1423
伪装坚强ぢ
伪装坚强ぢ 2020-11-28 07:30

Can we check whether a pointer passed to a function is allocated with memory or not in C?

I have wriiten my own function in C which accepts a character pointer -

18条回答
  •  一生所求
    2020-11-28 07:57

    I always initialize pointers to null value. Therefore when I allocate memory it will change. When I check if memory's been allocated I do pointer != NULL. When I deallocate memory I also set pointer to null. I can't think of any way to tell if there was enough memory allocated.

    This doesn't solve your problem, but you got to trust that if someone writes C programs then he is skilled enough to do it right.

提交回复
热议问题