{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

PassRefExample

# PassRefExample - Pass by Reference Tracing Example In...

This preview shows pages 1–3. Sign up to view the full content.

Pass by Reference Tracing Example In debugging and creating code, it’s imperative to understand the process the computer uses with both pass by value and pass by reference parameters. The following example illustrates the details of many situations that might arise. Keep in mind that the following code is NOT meant to be written to solve a problem. In fact, it’s intentionally written to be confusing. But, if one can trace through this example, she should be able to understand what is transpiring in any situation with function calls, at least with respect to the mechanics of what is going on. Here is the program: #include <stdio.h> int f1(int *a, int b); int f2(int a, int *b); int main() { int a = 5, b = 2, c = 7, d = 9; // line 8 c = f1(&d, a); // line 10 printf("a=%d,b=%d,c=%d,d=%d\n",a,b,c,d); // line 11 a = f2(c - d, &a); // line 12 printf("a=%d,b=%d,c=%d,d=%d\n",a,b,c,d); // line 13 b = f1(&c, 8); // line 14 printf("a=%d,b=%d,c=%d,d=%d\n",a,b,c,d); // line 15 d = f2(b, &a); // line 16 printf("a=%d,b=%d,c=%d,d=%d\n",a,b,c,d); // line 17 return 0;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
} int f1(int *a, int b) { // line 21 *a = b - 8; // line 22 b = b*2 - (*a); // line 23
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 7

PassRefExample - Pass by Reference Tracing Example In...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online