Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. // ConsoleApplication1.cpp : This file contains the 'main' function. Program execution begins and ends there.
  2. //
  3.  
  4. #include <iostream>
  5.  
  6. using namespace std;
  7.  
  8. struct SomeStruct {
  9. float a;
  10. float b;
  11. double c;
  12. double d;
  13. };
  14.  
  15. int main()
  16. {
  17. SomeStruct* someStruct = new SomeStruct;
  18. someStruct->a = 1.0f;
  19. someStruct->b = 2.0f;
  20. someStruct->c = 3.0f;
  21. someStruct->d = 4.0f;
  22.  
  23. float* floatpointer = (float*)(someStruct)+1;
  24. cout << *floatpointer << endl;//2
  25.  
  26. floatpointer = &(someStruct->a);
  27. cout << *floatpointer << endl;//1
  28.  
  29. floatpointer += 1;
  30. cout << *floatpointer << endl;//2
  31.  
  32. floatpointer += 1;//3
  33. cout << *floatpointer << endl;//0
  34.  
  35. double* doublePointer = (double*)floatpointer;
  36. cout << *doublePointer << endl;//3
  37.  
  38. doublePointer += 1;
  39. cout << *doublePointer << endl;//4
  40.  
  41. floatpointer += 2;
  42. doublePointer = (double*)(floatpointer);
  43.  
  44. cout << *doublePointer << endl;//4
  45. cout << (double*)floatpointer << endl;//address
  46.  
  47. return 0;
  48. }
  49.  
  50. // Run program: Ctrl + F5 or Debug > Start Without Debugging menu
  51. // Debug program: F5 or Debug > Start Debugging menu
  52.  
  53. // Tips for Getting Started:
  54. // 1. Use the Solution Explorer window to add/manage files
  55. // 2. Use the Team Explorer window to connect to source control
  56. // 3. Use the Output window to see build output and other messages
  57. // 4. Use the Error List window to view errors
  58. // 5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
  59. // 6. In the future, to open this project again, go to File > Open > Project and select the .sln file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement