|
| ripley (5) | |||||
| Hello, how do I return variables from function, that has arguments? For example:
Or should it look more like this?
When I want to call function f, how can I do that? Thanks, ripley | |||||
Last edited on | |||||
| DrChill (308) | |||||
| a: ask questions, do not chop half the words out. b: use the code tag instead of the quote tags. I recommend read this http://www.cplusplus.com/doc/tutorial/functions/ Aim for this: Hello, how do I return variables from function, that has aruments? For example:
Or should it look more like this?
When I want to call function f, how can I do that? Thanks, your name | |||||
Last edited on | |||||
| ripley (5) | |
| is that better? sorry, i thought you can see my name above. my english is not so well, sory. i havent find in the link u send what i was looking for. RIPLEY | |
| Duoas (2964) | |||
The first is more correct, but it has a fencepost error (there is no element b[5] -- only b[0], b[1], b[2], b[3], and b[4]), and the use of the array is not necessary. It is the same as saying:
Hope this helps. | |||
| herbert1910 (25) | |||
| ripley, your name is ripley. http://www.cplusplus.com/doc/tutorial/functions2/ arrays are passed by reference, not by value. the function can directly change your arrays. an easy way to get back b[] is to pass b[]:
| |||
| ripley (5) | |||
| no no, i sugest i didnt write it correctly. but what i want to do: i have some global fields, which has to be changed at some point, and thats why i wanted to use that function forexample f(), which is gonna make some operations with field and returns new field. than there is another function f2(), which take as an argument field - for first time field x, and second time changed field
the operations i used in f() i used just for ilustration. now i know, that first example i used above, where i was returning b[5] was wrong, because i was returning just one element. i was looking at the link you gaved me, but i am not more clever from that how to return field. i supose the best way is throug reference, but i have no idea how. thank you for you replies. | |||
| herbert1910 (25) | |||||
| ripley, your name is ripley. part of ripley's code:
b[] is a local variable in function f(). when f() returns, variables in f() may disappear! b[] could be gone! we will make b[] stay.
b[] is not a new array. do you want to allocate the space for a new array? | |||||
Registered users can post in this forum.
