C/Pointers
From Attie's Wiki
(Difference between revisions)
m (Created page with 'A helper for people starting out with pointers: <source lang="c"> #include <stdio.h> #include <stdlib.h> #include <ctype.h> #define P(expr) printf("%10s: 0x%02X\n", #expr, expr)…') |
Revision as of 23:08, 8 March 2012
A helper for people starting out with pointers:
#include <stdio.h> #include <stdlib.h> #include <ctype.h> #define P(expr) printf("%10s: 0x%02X\n", #expr, expr) int main(void) { char *s = "abc"; char **p = &s; P(s); P(&s); P(s[0]); P(*s); P(p); P(&p); P(p[0]); P(*p); P(p[1]); P(*p[1]); P((*p)[1]); P(*(p[1])); P((*p)); P((*p)++); P((*p)[0]); P((*p)); P(++(*p)); P((*p)[0]); P((*p)); return 0; }