#include<stdio.h>
#define SQUARE(a)((a)*(a))
int main()
{
int a=5;
int b;
b=SQUARE(a++);
printf("%d,%d\n",b,a);
return 0;
#define SQUARE(a)((a)*(a))
int main()
{
int a=5;
int b;
b=SQUARE(a++);
printf("%d,%d\n",b,a);
return 0;
}
输出结果是:25,7
不明白7的出现时因为什么
内存管理问题2
#include<stdio.h>
char *getmemory(void)
{
char p[]="hello world";
return p;
}
void test(void)
{
char *str=NULL;
str=getmemory();
printf(str);
}
int main(void)
{
test();
return 0;
}
问题1
#include<stdio.h>
void getmemory(char *p)
{
p=(char *)malloc(100);
}
void test(void)
{
char *str=NULL;
getmemory(str);
strcpy(str,"hello world");
printf(str);
}
int main(void)
{
test();
return 0;
}