Verify memory allocated

Hi,

int *p;
p = (int*)malloc(128);

Is there any mechanism to verify that the specified memory is allocated

Thanks
Yuvvy
YuvrajHSaunshiAsked:
Who is Participating?
 
hongjunConnect With a Mentor Commented:
try this

if ( (p = (int*)malloc(128)) == NULL )
{
    /* error */
}
0
 
TirumaleshwarCommented:
if( p != NULL){
........ success

}
esle
  {
...... failure
}
0
 
aib_42Commented:
Also, casting the return type of malloc() is a bad idea since it will suppress the warning message should you forget to include stdlib.h, which would result in undefined behaviour.
0
 
hongjunCommented:
if you are using gcc to compile, use this option to see all warning
    $> gcc -Wall yourfile.c


hongjun
0
All Courses

From novice to tech pro — start learning today.