Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

W40: call by value/reference

  • Loading branch information...
commit ba0c15717fae92da6c1e3f5a164e7e5bef075029 0 parents
@dr-itz authored
Showing with 29 additions and 0 deletions.
  1. +3 −0  .gitignore
  2. +4 −0 W40/Makefile
  3. +22 −0 W40/callbyvalue.c
3  .gitignore
@@ -0,0 +1,3 @@
+*.swp
+*.o
+test
4 W40/Makefile
@@ -0,0 +1,4 @@
+CC=gcc
+
+test:
+ $(CC) -o test callbyvalue.c
22 W40/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);
+}
Please sign in to comment.
Something went wrong with that request. Please try again.