Permalink
Browse files

W40: call by value/reference

  • Loading branch information...
0 parents commit ba0c15717fae92da6c1e3f5a164e7e5bef075029 @dr-itz committed Oct 1, 2012
Showing with 29 additions and 0 deletions.
  1. +3 −0 .gitignore
  2. +4 −0 W40/Makefile
  3. +22 −0 W40/callbyvalue.c
@@ -0,0 +1,3 @@
+*.swp
+*.o
+test
@@ -0,0 +1,4 @@
+CC=gcc
+
+test:
+ $(CC) -o test callbyvalue.c
@@ -0,0 +1,22 @@
+#include <stdio.h>
+
+void subByVal(int b)
+{
+ b = b - 1;
+}
+
+void subByRef(int *b)
+{
+ *b = *b - 1;
+}
+
+void main()
+{
+ int a = 10;
+
+ subByVal(a);
+ printf("surprise, suprise, it's still: %d\n", a);
+
+ subByRef(&a);
+ printf("by ref works better: %d\n", a);
+}

0 comments on commit ba0c157

Please sign in to comment.