Created
April 24, 2013 13:03
-
-
Save TheCodeEngine/5451964 to your computer and use it in GitHub Desktop.
A Stuct in a function example
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> | |
| typedef struct | |
| { | |
| const char *name; | |
| const char *species; | |
| int age; | |
| } turtle; | |
| void printTurtle(turtle *t) | |
| { | |
| /* | |
| Importent is that *t.name nicht das gleiche ist wie (*t).name | |
| - (*t).age or t->age = I am the age of the turtle pointed to by t | |
| - *t.age = I am the contents of the memory location given by t.age | |
| */ | |
| fprintf(stdout, "Name: %s\n", (*t).name); | |
| fprintf(stdout, "Species: %s\n", t->species); | |
| fprintf(stdout, "Age: %d\n", (*t).age); | |
| } | |
| int main(int argc, char const *argv[]) | |
| { | |
| turtle myturtle = { "Mytutrtle", "Leatherback sea turtle", 99 }; | |
| printTurtle(&myturtle); | |
| return EXIT_SUCCESS; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment