Got this code to analyze.
Code:
int i,m,*g_p;
int g[10]={1,5,3,4,0,22,8,0,-53,7};
main()
{
m=0;
g_p=g;
for (i=0;i<10;g_p++,m++,i++)
{
printf ("first loop: m=%d *g_p=%d\n",m, *g_p);
printf ("\n");
for (;*g_p;g_p++,i++);
printf ("second loop: m=%d *g_p=%d\n",m, *g_p);
printf ("\n");
}
printf ("end of program: m=%d *g_p=%d\n",m, *g_p);
}
Figured out that it calculates the numbers of series, delimited by 0. I don’t understand:
1. How does the pointer *g_p “jump” directly to 22 & then to -53.
2. Why does it get the value of 0?
3. What means the in
Code:
for (;*g_p;g_p++,i++);
output:
first loop: m=0 *g_p=1
second loop: m=0 *g_p=0
first loop: m=1 *g_p=22
second loop: m=1 *g_p=0
first loop: m=2 *g_p=-53
second loop: m=2 *g_p=0
end of program: m=3 *g_p=0