Created
December 16, 2016 12:19
-
-
Save joffilyfe/45a7cf4e69512b4c2fbcbe86a09aa82a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
typedef struct { | |
char street[60]; | |
} Address; | |
typedef struct { | |
char name[30]; | |
Address *first; | |
Address second; | |
} Person; | |
void initPerson(Person *p); | |
void changePerson(Person p); | |
int main() { | |
Person p; | |
initPerson(&p); | |
strcpy(p.name, "Nome do usuário"); | |
strcpy(p.first->street, "Primeira rua"); | |
strcpy(p.second.street, "Segunda rua"); | |
changePerson(p); | |
printf("%s\n", p.name); | |
printf("%s\n", p.first->street); | |
printf("%s\n", p.second.street); | |
return 0; | |
} | |
void initPerson(Person *p) { | |
Address *address; | |
address = malloc(sizeof(Address)); | |
if (address == NULL) { | |
return; | |
} | |
p->first = address; | |
} | |
void changePerson(Person p) { | |
strcpy(p.name, "Nome do usuário, modificado."); | |
strcpy(p.first->street, "Cópia de pessoa, rua modificada via ponteiro."); | |
strcpy(p.second.street, "Segunda rua modificada via cópia."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment