/*_______________________________________ I N T R O D U C T I O N T O P O I N T E R S CS121 Ron Kessler Created 10/24/2014 Visual Studio 2012 Updated: 10/28/2014- Fixed the format of the hex value returned by the pointers using String::Format({0:X}) style */ #pragma once namespace Intro2Pointers { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; using namespace System::Text; private: System::Void btnGo_Click(System::Object^ sender, System::EventArgs^ e) { //---get the names of the variables and assign the initial values try { int^ myInt = gcnew int; myInt =Convert::ToInt32(txtIntValue ->Text->Trim()); int^ *ptrInt =nullptr; ptrInt = &myInt; //Using String::Format() like this is called composite formatting, the "X" format provides formatting to hexadecimal. //---string hexOutput = String::Format("{0:X8}", value); X8 = 8 bytes String^ intLocHex = String::Format("{0:X8}", (UInt64)&ptrInt); // cast ptrInt type to unsigned int64 double nameOfDouble = Convert::ToDouble(txtDoubleValue->Text->Trim()); double *ptrDouble =nullptr; ptrDouble= &nameOfDouble; String^ doubleLocHex = String::Format("{0:X8}", (UInt64)&ptrDouble); // cast ptrDouble type to unsigned int64 String^ nameOfString = txtStringValue->Text->Trim(); String^ *ptrString = nullptr; ptrString = &nameOfString; String^ stringLocHex = String::Format("{0:X8}", (UInt64)&ptrString); // cast ptrString type to unsigned int64 //---now display it lblMemLocInt->Text =intLocHex; lblMemLocDouble->Text = doubleLocHex; lblMemLocString->Text = stringLocHex; } catch(Exception^ ex) { MessageBox::Show("An error occurred while getting this information." + ex->Message, "System Message", MessageBoxButtons::OK, MessageBoxIcon::Error); } } }; }