uni

University stuff
git clone git://git.christosmarg.xyz/uni-assignments.git
Log | Files | Refs | README | LICENSE

memalloc_ex1.c (548B)


      1 #include <stdio.h>
      2 #include <string.h>
      3 
      4 /* 
      5  * Make a student structure, assign a pointer to it and modify
      6  * it using the pointer
      7  */
      8 
      9 struct Student {
     10         char name[32];
     11         float avg;
     12 };
     13 
     14 int
     15 main(int argc, char *argv[])
     16 {
     17         struct Student stud = {"Foo Bar", 7.4f};
     18         struct Student *ptr;
     19 
     20         ptr = &stud;
     21         
     22         printf("stud.name: %s | stud.avg: %.2f\n", stud.name, stud.avg);
     23         strcpy(ptr->name, "Bar Baz");
     24         printf("ptr->name: %s | ptr->avg: %.2f\n", ptr->name, ptr->avg);
     25 
     26         return 0;
     27 }