This is an question on my textbook.
char array[26];
char *cptr = array;
char c;
for(c = 'A'; c<('A'+26);c++)
{
*cptr ++=c ;
printf("%d %c %d\n",cptr,c,c);
}
I want to know why the variety cptr in this line printf("%d %c %d\n",cptr,c,c); could print like
6487537 A 65
6487538 B 66
6487539 C 67
6487540 D 68
6487541 E 69
6487542 F 70
6487543 G 71
6487544 H 72
6487545 I 73
and not like constant
6487536 A 65
6487536 B 66
6487536 C 67
6487536 D 68
6487536 E 69
6487536 F 70
6487536 G 71
6487536 H 72
6487536 I 73
printf("%s", array);cptr++move the pointer%dis undefined behaviour. Use%pand cast the argument to(void *)*cptr ++=c ;, you wont have many friends.