Last active
February 26, 2018 20:01
-
-
Save joejulian/0031e2fb2dd4e072e66bf6cb4dff25fe 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 thing | |
{ | |
float height; | |
char * body; | |
} Thing; | |
int main(void) | |
{ | |
int *ptr_pJ2; | |
int pJ2 = 42; | |
Thing *ptr_thing = malloc(10*sizeof(Thing)); | |
// assign new pointer to point to value for var pJ | |
ptr_pJ2 = &pJ2; | |
// Referencing pointer to memory address of thing | |
Thing thing1 = *ptr_thing; | |
// assign pointer thing1 to reference struct Thing | |
thing1.height = 75.8; | |
thing1.body = strdup("fifth appendage"); | |
if ( thing1.body == 0 ) | |
{ | |
perror("Oops."); | |
} | |
printf("PJ2: %i\nbody: %s\nheight: %g\n", *ptr_pJ2, thing1.body, thing1.height); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment