Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

In and Out Parameters in C Programming - Prof. Marjory Baruch, Lab Reports of Computer Science

These notes explain the concept of in and out parameters in c programming, using examples of functions with both in and out parameters, and void functions. It also covers the use of pointers in passing arguments to functions.

Typology: Lab Reports

Pre 2010

Uploaded on 08/09/2009

koofers-user-6ih
koofers-user-6ih 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Notes on Lab 17: in and out parameters
I.
void replacewithdouble(int * num);
replacewithdouble needs a value for num in order to do the calculation.
So num is an in parameter.
But then the doubled value goes back to main by num, so num is also an out parameter.
To use replacewithdouble:
in main need a variable with a value
int i=5;
then call replacewithdouble(&i);
void justdouble(int x);
x is an in parameter, but there is no out parameter here so the answer is lost and never goes to main.
II
int makechange( int amount, int* q, int* d, int* n, int* p);
amount is an in parameter
q, d, n, p are out parameters only, but the arguments passed to them must be set up ahead of time so there
is someplace for the answers to go.
There is also a return value which can be copied to yet another variable.
1 of 2 3/22/09 9:55 PM
pf2

Partial preview of the text

Download In and Out Parameters in C Programming - Prof. Marjory Baruch and more Lab Reports Computer Science in PDF only on Docsity!

Notes on Lab 17: in and out parameters

I.

void replacewithdouble(int * num);

replacewithdouble needs a value for num in order to do the calculation. So num is an in parameter. But then the doubled value goes back to main by num , so num is also an out parameter. To use replacewithdouble: in main need a variable with a value

int i=5;

then call replacewithdouble(&i);

void justdouble(int x);

x is an in parameter , but there is no out parameter here so the answer is lost and never goes to main. II

int makechange( int amount, int* q, int* d, int* n, int* p);

amount is an in parameter q, d, n, p are out parameters only, but the arguments passed to them must be set up ahead of time so there is someplace for the answers to go. There is also a return value which can be copied to yet another variable. 1 of 2 3/22/09 9:55 PM

The function call:

n=makechange(amount, &quarters, &dimes, &nickles, &pennies);

2 of 2 3/22/09 9:55 PM