Print Floating Values using Pointer and Array in C++


This program allows the user to input 5 floating-point numbers and then displays them. First, it declares an array a of 5 floating-point numbers. It then prompts the user to enter 5 numbers using the cin function and stores them in the array using pointers with the notation *(a+i). Finally, it displays the 5 numbers using a for loop and the cout function, accessing each element of the array using a pointer with the notation *(a+i).

Source Code

#include<iostream>
using namespace std;
int main()
{
   float a[5];
   cout<<"Enter 5 numbers: ";
   for(int i=0;i<5;++i)
   {
    cin>>*(a+i);
   }
   cout<<"Displaying data: "<<endl;
   for(int i=0;i<5;++i)
   {
    cout<<*(a + i)<<endl ;
   }
   return 0;
}
To download raw file Click Here

Output

Enter 5 numbers: 12.3
45.5
56.7
89.7
90.7
Displaying data: 
12.3
45.5
56.7
89.7
90.7


Program List


Flow Control

IF Statement Examples


Switch Case


Goto Statement


Break and Continue


While Loop


Do While Loop


For Loop


Friend Function in C++


String Examples


Array Examples


Structure Examples


Structure & Pointer Examples


Structure & Functions Examples


Enumeration Examples


Template Examples


Functions


Inheritance Examples

Hierarchical Inheritance


Hybrid Inheritance


Multilevel Inheritance


Multiple Inheritance


Single Level Inheritance


Class and Objects

Constructor Example


Destructor Example


Operator Overloading Example


Operator and Function Example


List of Programs


Pointer Examples


Memory Management Examples


Pointers and Arrays


Virtual Function Examples