1 //17-pointers and arrays. CPP: The entry point that defines the console application. 2 //3 4#include"stdafx.h"5#include <iostream>6#include <climits>7 8 using namespacestd;9 Ten intMain () One { A inta[]{345, $, at,7,2,856, at, the,176}; -cout << a << Endl;//Output array is also output a string of addresses, the output address is the first element of the array address. Arrays are also pointers in C + +. - //If array A is a pointer, you can view the value of the pointer with the same *a, which should be 345. thecout << *a <<Endl; - //when the pointer is an array, you can add the subtraction operation, and +1 points to the next element in the array. -cout << * (A +1) << Endl;//the output value is - +* (A +1) = +;//a+1 refers to the second bit of an array and modifies the value of the second bit of array A to 1000. -cout << a[1] <<Endl; + A //so access to the array can be numbered not only by the array name, but also by pointers to the values in the array. at - //create an array using new. - int* p =New int[ -];//the active application of the memory is to delete -p[0] = -; -cout << p[0] <<Endl; - in* (P +2) = the;//modifies the value by pointer. -cout << p[2] <<Endl; to + Delete[] p;//If an array is requested, you have to use delete[] to delete the array p - the //It is recommended to create arrays in a normal way, pointers are used with caution! * $ intT;Panax NotoginsengCIN >>T; - return 0; the}
Fundamentals of C + + programming 117-pointers and arrays