// Native_myArrayays2.cpp : Defines the entry point for the console application. /*_______________________________________________________ W O R K I N G W I T H A R R A Y S P A R T 2 Pointers & myArrayays Demo Ron Kessler Created 1/7/2017 Native C++ Version This project demonstrates how to use a pointer to find values in an myArrayay as well as the memory location of the myArrayay elements. Since our array is using integers and each int uses 4 bytes, the memory locations you see are all 4 bytes apart but are contiguous. Run using CTL-F5 */ #include "stdafx.h" #include using namespace std; int main () { cout << "Working With Arrays Part 2\n\n"; int myArray [5] = {4,67,24,265,231}; //define our array int *ptr; //define a pointer of int type cout << "Here we display address of each element by using reference to elements in myArray: \n\n"; for (int i = 0; i < 5; ++i) { cout << "&myArray[" << i << "] = " << &myArray [i] << endl; } // ptr = &myArray[0] ptr = myArray; cout << "\nHere we display address using pointers: " << endl; for (int i = 0; i < 5; ++i) { cout << "ptr + " << i << " = " << ptr + i << endl; //ptr + i moves to the next elements location } cout << "\nNow let's view the data in each element using pointer notation: " << endl; for (int i = 0; i < 5; ++i) { cout << "myArray[" << i << "] = " << *(myArray + i) << endl; } return 0; //You can also assign values to elements by using pointer notation: /*cout << "Enter 5 numbers: "; for (int i = 0; i < 5; ++i) { cin >> *( myArray + i ); }*/ }