指针自加读整型数组的时侯读不出0元素,而且数组大小要比数组中非零元素的个数大,否则会读出随机数
#include<stdio.h>
#include<iostream>
using namespace std;
main()
{
int b[6]={5,8,3,4,0};
int* a=b;
while(*a)
{
cout<<*a<<endl;
a++;
}
return 0;
}
这种的结果是
5
8
3
4
#include<stdio.h>
#include<iostream>
using namespace std;
main()
{
int b[6]={5,8,3,4,1};
int* a=b;
while(*a)
{
cout<<*a<<endl;
a++;
}
return 0;
}
这种的结果是
5
8
3
4
1
#include<stdio.h>
#include<iostream>
using namespace std;
main()
{
int b[5]={5,8,3,4,1};
int* a=b;
while(*a)
{
cout<<*a<<endl;
a++;
}
return 0;
}
这种结果是
5
8
3
4
1
1703808
4332105
1
10228376
10228496
4331872
4331872
3842048