latest Post

Pointer yang menyalin sebuah array dengan C++

Berikut contoh program pointer yang menyalin sebuah array dengan menggunakan Dev-C++

#include <iostream>
using namespace std;

int main()
{
float A[8]={11.1, 33.3, 44.4, 55.5, 66.6, 77.7, 88.8, 99.9 };
float B[8]={22.2, 33.3, 44.4, 22.2, 66.6, 77.7, 11.1, 99.9 };
float C[8]={22.2, 11.1, 44.4, 55.5, 66.6, 77.7, 88.8, 11.1 };

int i;
float*aptr,*bptr,*cptr;
aptr=&A;
bptr=&B;
cptr=&C;

for (i=0; i<8; i++){
	cout<<*aptr<<"  ";
	*aptr++;
}

cout<<endl;
for (i=0; i<8; i++){
	cout<<*bptr<<"  ";
	*bptr++;
}

cout<<endl;
for (i=0; i<8; i++){
	cout<<*cptr<<"  ";
	*cptr++;
}

return 0;
}


About Unknown

Unknown
Recommended Posts × +

0 comments:

Post a Comment