Example 3: C++ Pointer and Array
C++ Program to insert and display data entered by using pointer notation.
#include <iostream>
using namespace std;
int main() {
float a[5];
// Inserting data using pointer notation
cout << "Enter 5 numbers: ";
for (int i = 0; i < 5; ++i) {
cin >> *(a+i) ;
}
// Displaying data using pointer notation
cout << "Displaying data: " << endl;
for (int i = 0; i < 5; ++i) {
cout << *(a+i) << endl ;
}
return 0;
}
Output
Enter 5 numbers: 2.5 3.5 4.5 5 2 Displaying data: 2.5 3.5 4.5 5 2
No comments:
Post a Comment