Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main() {
- int a=2;
- int *p=&a; /* *p = 1, p = 1004 */
- printf("Line 1: %u %u\n",*p, p);
- *p++;
- /*
- p++ = 1004 (incrementing p: operation not completed at)
- *(p++) = increment'ing' p..! it's pointer, allotted with int 4bits again so *p = 1008
- (==== it incrementing pointer not pointer pointing value. ====)
- *p = 1008
- */
- printf("Line 3: %u %u\n",*p, p);
- ++(*p);
- /*
- *p = 1008, p = 1008
- *p p's pointer
- p's incrementing p's pointer value, so p value (1008) added by 1.
- so p = (p + 1); p = 1008+1; p = 1009 and *p some come with some new location 3001
- */
- printf("Line 4: %u %u\n",*p, p);
- --p;
- /*
- (p = p-1) no more old pointer address but direct value.
- p = 1009-4; p = 1005; and some new random p's address *p = 3420
- */
- printf("Line 5: %u %u\n",*p, p);
- return 0;
- }
Add Comment
Please, Sign In to add comment