Created
April 1, 2014 03:42
-
-
Save heihachi/9907313 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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