Advertisement
ASP_Volume2 Miscellaneous #40796

Code Request - Using Pointers

My friend Joseph Harvey and I were talkin about pointers, so I made an example to express the concept.

AI

AIサマリー: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

ソースコード
original-source
/* Code Request - for Joseph Harvey
Using Pointers
  written by Jared Bruni
  www.LostSideDead.com
*/

#include<iostream>
using namespace std;

// using pointer to pass array
void fillarray(int* array, int size);
void disparray(int* array, int size);
int main()
{
	int value = 5;
	int *pointer = &value;// pointer now points to the address of value
	*pointer = 3;
	cout << "the address: " << pointer << endl; // ues nothing to indicate the address
	cout << "the value: " << *pointer << endl; // use the * to indicate you want the value
	                     // rather then the address
	system("pause");
	int values[25];
	fillarray(values,25);
	disparray(values,25);
	cout << " now for dynmaic allocation " << endl;
	system("pause");
  int* valuesx = new int [25];// dynmaicly allocate
	fillarray(valuesx,25);
	disparray(valuesx,25);
	delete [] valuesx;// delete off freestore
	valuesx = NULL;
	return (system("pause"));
}
// fill the array based on its size
void fillarray(int* array, int size)
{
	for(int i = 0; i < size; i++)
	{
		array[i] = rand()%420;
	}
}
// dispaly the array
void disparray(int* array, int size)
{
	for(int i = 0; i < size; i++)
	{
		cout << "value := " << array[i] << endl;
	}
}
オリジナルのコメント (3)
Wayback Machineから復元