#include <stdio.h>
#include <string.h>
#include <malloc.h>
//#define BB 1
#ifdef AA
void function(char **end)
{
printf("2 %p\n",end); //0xbfe8b3bc
printf("3 %p\n",*end);//0x9502008
printf("5 %s\n",*end);//打印字符串c
}
#elif defined BB
void function(char **end)
{
char cc[] = "jjjjjjjjjjjjjj";
printf("7 %p\n",cc); //0xbfc09011
printf("2 %p\n",end); //0xbfae74ac
printf("3 %p\n",*end);//null
printf("4 %s\n",*end);//打印字符串c,位空
*end = cc;
printf("6 %p\n",*end);//0xbfc09011
printf("5 %s\n",*end);//打印字符串cc
}
#else
void function(char *end)
{
printf("2 %p\n",end); //0x9d14008
printf("3 %p\n",*end); //打印字符串c的第一个字符j
printf("5 %s\n",end); //打印字符串c
}
#endif
int main()
{
#ifdef AA
char *end=NULL;
char c[] = "jxxxxxxxxf";
end = (char *)malloc(sizeof(char) * 10); //分配的起始地址为0x9502008
strcpy(end,c);
printf("1 %p %x\n",end,&end); //0x9502008 0xbfe8b3bc
/* end没有分配地址空间时,打印%p为null*/
function(&end);
printf("segement 1\n");
#elif defined BB
char *end=NULL;
printf("1 %p %x\n",end,&end); //null 0xbfae74ac
/* end没有分配地址空间时,打印%p为null*/
function(&end);
printf("segement 3\n");
#else
char *end=NULL;
char c[] = "jxxxxxxxxf";
end = (char *)malloc(sizeof(char) * 10); //分配的起始地址为0x9d14008
strcpy(end,c);
printf("1 %p %x\n",end,&end); //0x9d14008 0xbf8d491c
function(end);
printf("segement 2\n");
#endif
}
阅读(1097) | 评论(0) | 转发(0) |