Pass structure reference to a function - C++ Function

C++ examples for Function:Function Parameter

Description

Pass structure reference to a function

Demo Code

#include <iostream> 
#include <string> 
  
using namespace std; 
  
struct Player //  www . j  ava2s.c  om
{ 
        string m_name; 
}; 
  
void WelcomePlayer(Player& player) 
{ 
        cout << "Welcome to Text Adventure!" << endl << endl; 
        cout << "What is your name?" << endl << endl; 
  
        cin >> player.m_name; 
  
        cout << endl << "Hello " << player.m_name << endl; 
} 
int main(int argc, char *argv [])
{ 
        Player player; 
        WelcomePlayer(player); 
  
        return 0; 
}

Result


Related Tutorials