Skip to content

Instantly share code, notes, and snippets.

@LizardLeliel
Created November 13, 2014 22:04
Show Gist options
  • Save LizardLeliel/3c8a48173b181b0c8ca8 to your computer and use it in GitHub Desktop.
Save LizardLeliel/3c8a48173b181b0c8ca8 to your computer and use it in GitHub Desktop.
I was bored :V. Have fun
#include <stdlib.h>
typedef struct Node{void*data;int type;struct Node*next;}dynamicNode;int main()
{dynamicNode*first=(dynamicNode*)malloc(sizeof(dynamicNode));first->next=
(dynamicNode*)malloc(sizeof(dynamicNode));int m=4;float q=4.5;first->data=(void
*)(&m);first->next->data=(void*)(&q);printf("%f\n",(*(int*)first->data+*(float*
)first->next->data));int*a=(int*)malloc(sizeof(int));float*b=(float*)malloc(
sizeof(float));first->next->next=(dynamicNode*)malloc(sizeof(dynamicNode));
first->next->next->next=(dynamicNode*)malloc(sizeof(dynamicNode));first->next->
next->data=(void*)a;first->next->next->next->data=(void*)b;*a=5;*b=22.4;printf(
"%f\n",(*(int*)first->next->next->data+*(float*)first->next->next->next->data))
;first->type=0;first->next->type=1;first->next->next->type=0;first->next->next
->next->type=1;first->next->next->next->next=0;dynamicNode*tracker=first;float
o=0;while(tracker){if(tracker->type==0){o+=(float)*(int*)tracker->data;}else if
(tracker->type==1){o+=*(float*)tracker->data;}tracker=tracker->next;}printf(
"%f\n",o);return 0;}
/* Output:
8.500000
27.400000
35.900002
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment