Chinaunix首页 | 论坛 | 博客
  • 博客访问: 87297
  • 博文数量: 60
  • 博客积分: 4002
  • 博客等级: 中校
  • 技术积分: 645
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-17 18:11
文章分类

全部博文(60)

文章存档

2011年(60)

我的朋友

分类: C/C++

2011-03-30 22:20:14

{
  
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 */

}

 

阅读(259) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~