0
下面是它只打印单个值的代码如果我想打印整个数组,它不能正常工作。从C++中的指针数组打印值
#include <iostream>
using namespace std;
int *firstDay(int fd)
{
int d[35] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int setday = 1;
int *pnd;
pnd = d;
int limit = 35 - fd;
for(fd;fd<limit;fd++)
{
d[fd] = setday;
setday++;
}
return pnd;
}
void display(int *d)
{
cout<<d[1]<<endl; // value 0
cout<<d[2]<<endl; // value 1
cout<<d[3]; // value 2
}
int main()
{
display(firstDay(2));
return 0;
}
如果我只写一个cout
那么它的工作原理和打印正确的值如果我使用一个以上的cout
那么就不能打印正确的值。
把数组d [35] = {...}外函数FirstDay并应该工作。 – maciekm