Last active
August 18, 2017 06:54
-
-
Save yarcowang/40364ac0fc1908104423def6f61e6a6e to your computer and use it in GitHub Desktop.
simple c code
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 <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
typedef struct { | |
char name[10]; | |
} Person; | |
int main() { | |
// initialize to empty | |
Person* p = NULL; | |
// check if empty do memory allocated | |
if (!p) { | |
p = (Person*) malloc(sizeof(Person)); | |
} | |
// set the name | |
strcpy(p->name, "yarco"); // the meaning is the same as `p->name = "yarco"` | |
printf("I'm %s\n", p->name); | |
// free memery | |
free(p); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If remove
types
andmemory management
, the code is much more like this:in my mind...