Example 1 - Homework 1, Problem 2 1 void op1(int a, int b) { 2 a = a + b; 3 } 4 5 void op2(int* a, int* b) { 6 *a = *a + *b; 7 } 8 9 int main() { 10 int a = 1, b = 1, c = 1, d = 1; 11 op1(a, b); 12 op2(&c, &d); 13 return 0; 14 } Example 2 - Homework 1, Problem 4 1 int a[5]; 2 3 a[0] = 0; 4 a[1] = 10; 5 a[2] = 100; 6 7 //COMMENT 1 8 9 a[3] = *a + 2; 10 a[4] = *(a + 2); 11 12 //COMMENT 2 Example 3: 1 struct bar { 2 int k; 3 }; 4 5 struct foo { 6 int a; 7 struct bar b; 8 }; 9 10 int main() { 11 const int NFOO = 5; 12 struct foo foo_array[NFOO]; 13 struct foo* foo_p = 0; 14 int i = 0; 15 16 for (; i < NFOO; ++i) { 17 foo_array[i].a = i; 18 foo_array[i].b.k = 0; 19 foo_p = &foo_array[i]; 20 if (foo_p->a > 2) { 21 foo_p->b.k = 10; 22 } 23 printf("%d %d\n", foo_p->a, foo_p->b.k); 24 } 25 26 return 0; 27 } Example 4: 1 struct item { 2 int price; 3 int quantity; 4 }; 5 6 int compute_total_price(struct item i) { 7 return i.price * i.quantity; 8 } 9 10 void double_quantity(struct item i) { 11 i.quantity *= 2; 12 } 13 14 void double_price(struct item* i) { 15 i->price *= 2; 16 } 17 18 int main() { 19 struct item my_item; 20 my_item.price = 25; 21 my_item.quantity = 100; 22 printf("%d\n", compute_total_price(my_item)); 23 24 double_quantity(my_item); 25 printf("%d\n", compute_total_price(my_item)); 26 27 double_price(&my_item); 28 printf("%d\n", compute_total_price(my_item)); 29 30 return 0; 31 }