Chinaunix首页 | 论坛 | 博客
  • 博客访问: 359720
  • 博文数量: 100
  • 博客积分: 2500
  • 博客等级: 大尉
  • 技术积分: 1209
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-15 21:24
文章分类

全部博文(100)

文章存档

2011年(100)

分类: C/C++

2011-04-22 09:36:07

Example:

{
  
char *dp = NULL;
  
/* ... */
  
{
      
char c;
      dp 
= &c;
  
} /* c falls out of scope */
    
/* dp is now a dangling pointer */
}

#include 
void func()
{
   
char *dp = malloc(A_CONST);
   
/* ... */
   free
(dp);         /* dp now becomes a dangling pointer */
   dp 
= NULL;        /* dp is no longer dangling */
   
/* ... */
}

int *func(void)
{
   
int num = 1234;
   
/* ... */
   
return #
}

int f(int i)
{
   
char *dp;    /* dp is a wild pointer */
   
static char *scp;  /* scp is not a wild pointer:
                       * static variables are initialized to 0
                       * at start and retain their values from
                       * the last call afterwards.
                       * Using this feature may be considered bad
                       * style if not commented */

}


阅读(1231) | 评论(1) | 转发(0) |
0

上一篇:strcpy & memcpy

下一篇:类和结构体

给主人留下些什么吧!~~

onezeroone2011-04-24 16:04:25

tatic variables are initialized to 0