Skip to content

Instantly share code, notes, and snippets.

@jmcph4
Created January 22, 2015 23:03
Show Gist options
  • Select an option

  • Save jmcph4/179e0d0ae1494c2fa2f8 to your computer and use it in GitHub Desktop.

Select an option

Save jmcph4/179e0d0ae1494c2fa2f8 to your computer and use it in GitHub Desktop.
Fun in the Sun with...pointers! *queue game show music from 80s*
#include <iostream>
int main(void)
{
int i = 37;
float f = i;
float g = *(float*)&i;
int* j = &i;
int* k = j;
int l = *j;
std::cout << "i=" << i << std::endl;
std::cout << "f=" << i << std::endl;
std::cout << "g=" << g << std::endl;
std::cout << "j=" << j << std::endl;
std::cout << "k=" << k << std::endl;
std::cout << "l=" << l << std::endl;
std::cout << std::endl << "i = 27" << std::endl << std::endl;
i = 27;
std::cout << "i=" << i << std::endl;
std::cout << "f=" << i << std::endl;
std::cout << "g=" << g << std::endl;
std::cout << "j=" << j << std::endl;
std::cout << "k=" << k << std::endl;
std::cout << "l=" << l << std::endl;
std::cout << std::endl << "j++" << std::endl << "l = *j" << std::endl << std::endl;
j++;
l = *j;
std::cout << "i=" << i << std::endl;
std::cout << "f=" << i << std::endl;
std::cout << "g=" << g << std::endl;
std::cout << "j=" << j << std::endl;
std::cout << "k=" << k << std::endl;
std::cout << "l=" << l << std::endl;
std::cout << std::endl << "j + sizeof(int) (sizeof(int) = " << sizeof(int) << ")" << std::endl << "l = *j" << std::endl << std::endl;
j + sizeof(int);
l = *j;
std::cout << "i=" << i << std::endl;
std::cout << "f=" << i << std::endl;
std::cout << "g=" << g << std::endl;
std::cout << "j=" << j << std::endl;
std::cout << "k=" << k << std::endl;
std::cout << "l=" << l << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment