// ========================================================================== // $Id: int_pointer.cpp,v 1.4 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: int_pointer.cpp,v $ // Revision 1.4 2014/09/10 17:18:02 jlang // Added char_num_pointer example. Changed to C++ brace initialization. // // Revision 1.3 2008/09/08 21:48:32 jlang // Clearer size computation // // Revision 1.2 2007/09/12 18:37:00 jlang // Extra comments // // Revision 1.1 2006/09/07 20:06:17 jlang // Initial check-in lecture 0-2 // // // ========================================================================== #include using std::cout; using std::endl; int main() { int numbers[]{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 }; int *ptrNumber; ptrNumber = &numbers[0]; // Number at first and last index cout << *ptrNumber << " to " << *(ptrNumber+17) << endl; // Address of first and last index cout << ptrNumber << " to " << (ptrNumber+17) << endl; // Difference between last and first in bytes cout << "Array Length (Bytes): " << (size_t) (ptrNumber+17) - (size_t) ptrNumber + 1 * sizeof(int) << endl; }