70,020
社区成员




#include<stdio.h>
struct test
{
int x;
int cur;
};
struct test *create(int n)
{
struct test L[100];
int i;
L[0].cur = 1;
for (i = 1; i <=n; i++)
{
scanf("%d", &L[i].x);
L[i].cur = i + 1;
}
return L;
}
int Locate(struct test *L,int e)
{
int i;
i = L[0].cur;
while (i&&L[i].x != e)
i = L[i].cur;
return i;
}
void print(struct test *L,int n)
{
int i;
for (i = 1; i <= n; i++)
{
printf("%d\n", L[i].x);
}
}
int main()
{
struct test *S;
int n,e,a;
printf("请输入要创建的链表数:");
scanf("%d", &n);
S = create(n);
printf("请输入要查找的数字:");
scanf("%d", &e);
printf("%d", Locate(S, e));
}
#include<stdio.h>
int *kk()
{
int a[2] = { 1, 2 };
return a;
}
int main()
{
int *b;
b = kk();
printf("%d", b[0]);
}
那请问一下为什么a没有被释放,可以打印出来。。小白勿喷。。struct test L[100];
改成struct test ×L = (struct test *)malloc(sizeof(struct test)*n)
#include<stdio.h>
int *kk()
{
int a[2] = { 1, 2 };
return a;
}
int main()
{
int *b;
b = kk();
printf("%d", b[0]);
}
那请问一下为什么a没有被释放,可以打印出来。。小白勿喷。。[/quote]
我终于弄明白了,如果在printf前面再加个printf栈内存就被覆盖了,而堆就不会,谢谢大家