#include "stdafx.h"
#include %26lt;iostream%26gt;
using namespace std;
void print (int* a, int* b, int arraySize) {
int* aPtr;
int* bPtr;
int i;
cout %26lt;%26lt; "The values:" %26lt;%26lt; endl;
for (i = 0, aPtr = a, bPtr = b; i %26lt; arraySize;
cout %26lt;%26lt; "A[" %26lt;%26lt; i %26lt;%26lt; "]: " %26lt;%26lt; *(aPtr++) %26lt;%26lt; endl,
cout %26lt;%26lt; "B[" %26lt;%26lt; i %26lt;%26lt; "]: " %26lt;%26lt; *(bPtr++) %26lt;%26lt; endl, i++);
}
int main() {
const int arraySize = 10;
int* a = new int[arraySize];
int* b = new int[arraySize];
int* aPtr;
int* bPtr;
int i;
// initialise
for (i = 0, aPtr = a, bPtr = b; i %26lt; arraySize; *(aPtr++) = 1, *(bPtr++) = 2, i++);
// print
print(a, b, arraySize);
// copy
for (i = 0, aPtr = a, bPtr = b; i %26lt; arraySize; *(aPtr++) = *(bPtr++), i++);
// print
print(a, b, arraySize);
}
How to make an array using pointers in C++?
void main()
{
int i;
int *ar[10];
int num[10];
for( i=0;i%26lt;10;i++)
{
ar[i]=%26amp;(num[i]);
}
for(i=0;i%26lt;10;i++)
{
cout%26lt;%26lt; *(ar[i]);
}
getch();
}
Reply:try this link
http://www.intap.net/~drw/cpp/
Reply:array a[15]
a[0]=9;
a[0]-%26gt;next=a[1]=4;
......
you have to define next before you use it as global variable
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment