What if I want to call a function that scans for two integers then processes then the results will be then passed on another function then it will process it then the same thing happens again for the second time (I think) What would it look like? Please be more specific in the ampersand and pointer part like void printSomething(int *a,int *b)
Syntax wise, you've got it for C. For C++, you may need to make them a reference to the pointer. Since you'd be working on a common set of numbers, it's no bad to do the calls. Since you're working ON the numbers, you have no return problems. The main thing is that that logic is a bit convoluted.
how will it look like can you type an example for me??? I would appreciate it by giving some medals. xD
If you're calling a function that operates on a pointer/reference (I still don't know if we're talking C or C++), any changes to the value ( *a ) will change the value of the calling function's variable. So you can return void from the called function. The reason for passing pointers/references in C/C++ is that the called function gets a copy of the passed variables. If pointers/references are passed, the copy still points to the value, so any value changes in the function persist after the function returns. If the function is passed a copy of the value, and it's changed, it's destroyed when the function returns and it's stack frame is cleaned up.
Join our real-time social learning platform and learn together with your friends!