Skip to content

Instantly share code, notes, and snippets.

@PhDP
Created March 29, 2012 10:21
Show Gist options
  • Save PhDP/2235673 to your computer and use it in GitHub Desktop.
Save PhDP/2235673 to your computer and use it in GitHub Desktop.
Pointer examples
#include <stdlib.h>
#include <stdio.h>
int main()
{
int a = 5;
int *b = &a;
printf(" a = %d\n", a);
printf(" &a = %p\n", &a);
printf(" b = %p\n", b);
printf(" *b = %d\n", *b);
printf(" b[0] = %d\n", b[0]);
int *c = malloc(5 * sizeof(int));
int i = 0;
for (; i < 5; ++i)
{
c[i] = 5 * i;
}
printf(" c = %p\n", c);
printf(" (c + 3) = %p\n", c + 3);
printf(" c[3] = %d\n", c[3]);
printf(" &c[3] = %p\n", &c[3]);
printf(" *(c + 3) = %d\n", *(c + 3));
free(c);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment