// ========================================================================== // $Id: char_num_pointer.cpp,v 1.1 2014/09/10 17:18:02 jlang Exp $ // CSI2372 example Code for lecture 2 // ========================================================================== // (C)opyright: // // Jochen Lang // SITE, University of Ottawa // 800 King Edward Ave. // Ottawa, On., K1N 6N5 // Canada. // http://www.site.uottawa.ca // // Creator: jlang (Jochen Lang) // Email: jlang@site.uottawa.ca // ========================================================================== // $Log: char_num_pointer.cpp,v $ // Revision 1.1 2014/09/10 17:18:02 jlang // Added char_num_pointer example. Changed to C++ brace initialization. // // // ========================================================================== #include using std::cout; using std::endl; int main() { char numbers[]{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 }; char *ptrNumber; ptrNumber = &numbers[0]; // Number at first and last index cout << static_cast(*ptrNumber) << " to " << static_cast(*(ptrNumber+17)) << endl; // Address of first and last index cout << (size_t)(ptrNumber) << " to " << (size_t)(ptrNumber+17) << endl; // Difference between last and first in bytes cout << "Array Length (Bytes): " << sizeof(numbers) << endl; cout << std::hex; // Address of first and last index - now printed in hex cout << (size_t)(ptrNumber) << " to " << (size_t)(ptrNumber+17) << endl; // Difference between last and first in bytes - now printed in hex cout << "Array Length (Bytes): " << sizeof(numbers) << endl; }