question about incrmenting pointer vs array?
why does this print "12345"
Code:
#include<stdio.h>
int main()
{
int num[] = {1,2,3,4,5};
int *pnum = num;
for(pnum;pnum <= num+4;pnum++)
printf("%d",*pnum);
return 0;
}
but this doesn't work (just prints garbage values)
Code:
#include<stdio.h>
int main()
{
int num[] = {1,2,3,4,5};
int *pnum = num;
for(pnum;pnum <= pnum+4;pnum++)
printf("%d",*pnum);
return 0;
}
if num and pnum have the same starting address and you can increment pnum as pnum++, why doesn't pnum+4 = num+4
thanks