By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,507 Members | 1,758 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,507 IT Pros & Developers. It's quick & easy.

a special type of function

P: n/a
Hi,

I want to write function that is of type: void Funt(long az, double
bt, long *ar1, double *ar2)
I got the function to work for the arrays: ar1 and ar2 but I don't
know how to get it to work for variables: az and bt.

Can anyone show me if and how this is possible.

Thanks,
/Sheldon
Nov 14 '08 #1
Share this Question
Share on Google+
3 Replies


P: n/a
On Nov 14, 1:15*pm, Sheldon <shejo...@gmail.comwrote:
Hi,

I want to write function that is of type: void Funt(long az, double
bt, long *ar1, double *ar2)
I got the function to work for the arrays: ar1 and ar2 but I don't
know how to get it to work for variables: az and bt.
If you want to modify the contents of the variables az and bt, you
have to pass their addresses.
In C, all objects passed into functions are copies of the original.
So if you want to change the original object, just pass in the address
of the object and manipulate it that way.

This is just my guess, and my Karnak hat has gone missing so if you
really want to know about something else, you might spell out exactly
what you have tried and exactly what is going wrong, along with a copy/
paste of the actual code you are using.
Nov 14 '08 #2

P: n/a
Sheldon wrote:
Hi,

I want to write function that is of type: void Funt(long az, double
bt, long *ar1, double *ar2)
I got the function to work for the arrays: ar1 and ar2 but I don't
know how to get it to work for variables: az and bt.

Can anyone show me if and how this is possible.
#include <stdio.h /* for illustrative purposes */

void Funt(long az, double bt, long *ar1, double *ar2) {
printf ("az = %ld\n", az);
printf ("bt = %g\n", bt);
if (ar1 != NULL)
printf ("*ar1 = %ld\n", *ar1);
if (ar2 != NULL)
printf ("*ar2 = %g\n", *ar2);
}

int main(void) {
long uu[] = { 42, 21, -8 };
double vv[] = { 42.1, -39.7, 88.44, 22.0/7 };
Funt (123456789, 98.6, uu, vv);
return 0;
}

--
Er*********@sun.com
Nov 14 '08 #3

P: n/a
On 14 Nov, 22:30, user923005 <dcor...@connx.comwrote:
On Nov 14, 1:15*pm, Sheldon <shejo...@gmail.comwrote:
Hi,
I want to write function that is of type: void Funt(long az, double
bt, long *ar1, double *ar2)
I got the function to work for the arrays: ar1 and ar2 but I don't
know how to get it to work for variables: az and bt.

If you want to modify the contents of the variables az and bt, you
have to pass their addresses.
In C, all objects passed into functions are copies of the original.
So if you want to change the original object, just pass in the address
of the object and manipulate it that way.

This is just my guess, and my Karnak hat has gone missing so if you
really want to know about something else, you might spell out exactly
what you have tried and exactly what is going wrong, along with a copy/
paste of the actual code you are using.
Thanks! It works!

/M
Nov 14 '08 #4

This discussion thread is closed

Replies have been disabled for this discussion.