msdn上说了:If no error occurs, inet_ntoa returns a character pointer to a static buffer containing the text address in standard ".'' notation. Otherwise, it returns NULL. 返回的指针指向系统内部的一个静态的缓冲区,应该是在你的程序的执行过程中都不会释放,每一次调用inet_ntoa都会返回同一个指针,但是缓冲区内容被修改了。可以认为这个空间在程序退出的时候才释放。
全局的话,程序退出以后会自动由系统收回。
一般而言delete 对应的只是 new出来的东西。
char FAR * p = inet_ntoa(addr_in);//inet_ntoa返回了就没有了,p也丢失了
..... //开始使用
.....
..... //使用完
delete p;
这样做本身就是错误的,应该这么写
char s[ 100 ];
memset( s, 0, 100 );
strcat( s, inet_ntoa( addr_in ) );printf也有返回值,不过大家平常丢掉了