Computing.Net > Forums > Programming > Passing a function

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Passing a function

Reply to Message Icon

Name: JB
Date: May 11, 2003 at 14:15:25 Pacific
OS: WindowsXP
CPU/Ram: pentium4 (wish i had amd)
Comment:

I cant figure out how to pass an array say int x[5]; to a function so that function can access it. I'd like to just be able to pass it the values in the array without manually passing each individual elements.

Thanx
PS i use dev 4 C++



Sponsored Link
Ads by Google

Response Number 1
Name: kev
Date: May 11, 2003 at 14:28:55 Pacific
Reply:

Try sending it just the variable, which would be just 'x'. So at the top, you would declare your functions like:

int Function(value[5]);

Then you would call it like:

result = Function(x);

And the function would look like:

int Function(value[5])
{
// do stuff
}

That should do it.

Kev


0

Response Number 2
Name: JB
Date: May 12, 2003 at 07:03:43 Pacific
Reply:

sorry, i didnt explain right, realized what you saw from what i said ;]


i mean is there anyway like to pass from int main() and funct call


ie

int array(int);

int main()
{


array();
return 0;
}

int array(x[51]) //51 elements
{
array[1]=x[0]
array[1]=4;
array[2]=3;
array[3]=array[1] + array[2];
return array[3];
}

sorta like this, thanx again


0

Response Number 3
Name: muska
Date: May 12, 2003 at 09:16:45 Pacific
Reply:

I think there is a way that you can set a parameter in the function prototype to be an array, something like

void myFunction(int myvalue[]);

and then you just say

myFunction(arrayName);


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


Pascal Arrays MS Voice Text error, plea...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Passing a function

Passing a string to a function www.computing.net/answers/programming/passing-a-string-to-a-function/6733.html

ISAPI & to override a function. www.computing.net/answers/programming/isapi-amp-to-override-a-function/849.html

passing a var-name by string in c# www.computing.net/answers/programming/passing-a-varname-by-string-in-c/6271.html