344-memoryallocation.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
#include <stdio.h> #include <stdlib.h> #include <string.h> struct student { char fname[25]; int id, age; }; int g(int i, int j){ int r = i+j; return r+1; } int f(int k){ k += g(k, k); return k; } void print_student(struct student s){ printf("%s - age: %d, id: %d\n",s.fname, s.age, s.id); } struct student inc_age(struct student s){ s.age++; print_student(s); return s; } void stackCount(){ int i = 0; printf("i: %d\n", ++i); } void staticCount(){ static int i; printf("i: %d\n", ++i); } int main(void) { int l = 5; int m = f(l); printf("l: %d, m: %d\n",l,m); struct student s1; s1.id = 800; s1.age = 19; strcpy(s1.fname, "Jamie"); print_student(s1); s1 = inc_age(s1); print_student(s1); stackCount(); stackCount(); stackCount(); staticCount(); staticCount(); staticCount(); return EXIT_SUCCESS; } |