473,320 Members | 1,839 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

a special type of function

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
3 1306
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: david.lindsay.green | last post by:
Hello all, I am quite new a web scripting and making web pages in general and I have stumbled across a problem I have as yet been unable to solve. I am trying to take the contents of a textarea box...
7
by: Ben Finney | last post by:
Howdy all, Ned Batchelder blogged about a debate over checking function parameters, and to what extent dynamic typing should be relied upon. I was one of many who commented, but I wrote what...
1
by: Raj B | last post by:
Hi My question is about how special methods are stored internally in Python objects. Consider a new-style class which implements special methods such as __call__ and __new__ class C(type):...
5
by: Joseph Barillari | last post by:
Hi python-list, I've just started using new-style classes and am a bit confused as to why I can't seem to alter methods with special names (__call__, etc.) of new-style class instances. In other...
2
by: buchtak | last post by:
Hi, can I define type of a variable based on some other type using templates? For example I have template <typename T> struct A { T t; U x; }; and I want to define U, such that if T is...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.