PassRefExample - Pass by Reference Tracing Example In...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Pass by Reference Tracing Example In debugging and creating code, its 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, its 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; }...
View Full Document

This note was uploaded on 06/09/2011 for the course COP 3223 taught by Professor Guha during the Spring '08 term at University of Central Florida.

Page1 / 7

PassRefExample - Pass by Reference Tracing Example In...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online