Parameter Passing

# Parameter Passing - print(sum,avg Main first using...

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

// This program demonstrates reference and value parameter passing #include <stdio.h> //functions first //value: one-way communication: no * //reference: two-way communication: use * void load(int *a,int *b,int *c) { printf("Enter 3 values"); scanf("%d%d%d",&*a,&*b,&*c); } void calc(int d,int e,int f,int *sum,float *avg) { *sum=d+e+f; *avg=*sum/(float)3; } void print(int sum,float avg) { printf("The sum is %d\n",sum); printf("The average is %f\n",avg); } void main() { int x,y,z,sum; float avg; load(&x,&y,&z); //in function call, use & for reference parameters; matches order calc(x,y,z,&sum,&avg);

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: print(sum,avg); } /* Main first using prototypes void load(int *,int *,int *); void calc(int,int,int,int *,float *); void print(int,float); void main() { int x,y,z,sum; float avg; load(&x,&y,&z); calc(x,y,z,&sum,&avg); print(sum,avg); } void load(int *a,int *b,int *c) { printf("Enter 3 values"); scanf("%d%d%d",&(*a),&(*b),&(*c)); } void calc(int d,int e,int f,int *sum,float *avg) { *sum=d+e+f; *avg=*sum/(float)3; } void print(int sum,float avg) { printf("The sum is %d\n",sum); printf("The average is %f\n",avg); } */...
View Full Document

{[ snackBarMessage ]}

### Page1 / 2

Parameter Passing - print(sum,avg Main first using...

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

View Full Document
Ask a homework question - tutors are online