Demonstrate passing structure as argument - C++ Data Type

C++ examples for Data Type:struct

Description

Demonstrate passing structure as argument

Demo Code

#include <iostream>
using namespace std;
struct Measure//from w  w  w  .j  a  v a 2s  .  c o  m
{
   int feet;
   float inches;
};
void engldisp( Measure );     //declaration
int main()
{
   Measure d1, d2;
   cout << "Enter feet: ";  cin >> d1.feet;
   cout << "Enter inches: ";  cin >> d1.inches;
   cout << "\nEnter feet: ";  cin >> d2.feet;
   cout << "Enter inches: ";  cin >> d2.inches;
   cout << "\nd1 = ";
   engldisp(d1);               //display length 1
   cout << "\nd2 = ";
   engldisp(d2);               //display length 2
   cout << endl;
   return 0;
}
// display structure of type Measure in feet and inches
void engldisp( Measure dd )   //parameter dd of type Measure
{
   cout << dd.feet << "\'-" << dd.inches << "\"";
}

Result


Related Tutorials