Storing an address in a structure member - C++ Data Type

C++ examples for Data Type:struct

Description

Storing an address in a structure member

Demo Code

#include <iostream>
#include <iomanip>
using namespace std;
struct Test//from   ww w  . j  av a  2  s . c om
{
   int id;
   double *ptPay;
};
int main()
{
   Test emp;
   double pay = 456.20;
   emp.id = 12345;
   emp.ptPay = &pay;
   cout << setw(6) << setiosflags(ios::fixed) << setiosflags(ios::showpoint) << setprecision(2);
   cout << "\nEmployee number " << emp.id << " was paid $" << *emp.ptPay << endl;
   return 0;
}

Result


Related Tutorials