Skip to content

Instantly share code, notes, and snippets.

@plasmatic1
Last active May 20, 2018 14:14
Show Gist options
  • Save plasmatic1/feb3c84eb459bc1d54f20bb5187868c9 to your computer and use it in GitHub Desktop.
Save plasmatic1/feb3c84eb459bc1d54f20bb5187868c9 to your computer and use it in GitHub Desktop.
Having fun with pointers
#include <bits/stdc++.h>
using namespace std;
inline const char* tf(bool b){
return ((b) ? "true" : "false");
}
int main()
{
int a = 5, b = 6, c = 7;
int *p = &a;
printf("value of a: %d, value of b: %d\n\n", *p, *(p + 1));
p++;
printf("p+1 == &b: %s\n", tf(p == &b)); //Go home c++, you're drunk
printf("&b - (p+1): %d\n", p - &b);
printf("addr of &b: %p\n", &b);
printf("addr of (p+1): %p\n", p);
printf("value at &b: %d, value at (p+1): %d\n", *(&b), *p);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment