帮忙解决一下。。。急
#include<stdio.h>#define SIZE 10
void main()
{
int i,*base,*top;
int a[10];
base=a;
top=base;
while(i<=10)
{
scanf("%d",top);
top++;
i++;
}
do
{
printf("%d",*top--);
}while(top!=base);
}
编译没问题。。可是运行的时候就行不通啦为撒啊
----------------解决方案--------------------------------------------------------
首先,scanf函数没写 & 低级错误!
其次,没搞明白,数组在内存中的存放形式,
top-- 错误!
难道,整型数组的一个元素在内存中大小为 1 ??
----------------解决方案--------------------------------------------------------
楼上你的理解错误,他用的是指针
关键是i=0在循环前需要i给个初值 ----------------解决方案--------------------------------------------------------
scanf("%d",top);
后更%f
----------------解决方案--------------------------------------------------------
不好意思说错了!
是scanf后面跟%f
----------------解决方案--------------------------------------------------------
#include<stdio.h>
#define SIZE 10
void main()
{
int i,*base,*top;
int a[11];
i=0;
base=a;
top=base;
while(i<=10)
{ printf("请输入第%d个得值:",i);
scanf("%d",top);
top++;
i++;
}
do
{ top=top--;
printf("输出值:");
printf("%d\n",*top);
}while(top!=base);
}
----------------解决方案--------------------------------------------------------
数组益出啊.你定义10个大小的数组,最多到a[9]啊
----------------解决方案--------------------------------------------------------
哈哈,那就给i=1就成了,反正i 只用于计数,没做数组下标,个数对了就行.
----------------解决方案--------------------------------------------------------
#include<stdio.h>
#define SIZE 10
void main()
{
int i,*base,*top;
int a[10];
base=a;
top=base;
while(i<=10) //i为初始化
{
scanf("%d",top);
top++;
i++;
}
do
{
printf("%d",*top--); //越界 应该*--p
}while(top!=base);
}
----------------解决方案--------------------------------------------------------
/*编译通过*/
#include<stdio.h>
#define SIZE 10
void main()
{
int i=0,*base,*top;
int a[10];
base=a;
top=base;
while(i<10)
{
scanf("%d",top);
top++;
i++;
}
do
{
top--;
printf("%d ",*top);
getch();
}while(top!=base);
}
----------------解决方案--------------------------------------------------------