Last active
May 20, 2018 14:14
-
-
Save plasmatic1/feb3c84eb459bc1d54f20bb5187868c9 to your computer and use it in GitHub Desktop.
Having fun with pointers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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