Skip to content

Instantly share code, notes, and snippets.

@heihachi
Created April 1, 2014 03:42
Show Gist options
  • Save heihachi/9907313 to your computer and use it in GitHub Desktop.
Save heihachi/9907313 to your computer and use it in GitHub Desktop.
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
struct Name
{
string first;
string second;
};
struct person
{
Name name;
string address;
};
// this will pass by reference
bool setPerson(person *person1)
{
person1->name.first = "James";
person1->name.second = "Bishop";
person1->address = "Concord";
return true;
}
bool printStruct(person temp)
{
// output all the data in structure
printf("Hello, %s %s! You live at %s\n", temp.name.first.c_str(), temp.name.second.c_str(), temp.address.c_str());
return true;
}
int main()
{
// declare a struct
person newPerson;
// call function use & for the * in the function to pass by reference
setPerson(&newPerson);
// dont need & here since we arent changing any data
printStruct(newPerson);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment