Okay so I declared a function and an array as its arrgument(and seperatly), then
ID: 3527814 • Letter: O
Question
Okay so I declared a function and an array as its arrgument(and seperatly), then in another function I assign the array as equal to another array. I know that before it leaves the function i which it is given a value that said value is correct. when the function using it as an arrgument runs though the array has no value, even though it is declared seperatly and as an argument on the global scale, it is passed in the first function as myfunc2(arrayName);, and it is also declared as an arrgument when I declare the function trying to use it.Explanation / Answer
passing array to a function works EXACTLY like pass by reference. Anything done to the array in the function would affect the original array. When you pass in that array, you are actually passing in the pointer to the first address of the first element, but unless you are using Java, you need to also send in the length of that array so that the function knows when that array ends. THe only exception to the above would be if you used the const keyword. That would stop any changes to the original array by the function even though it is declared seperatly and as an argument on the global scale, it is passed in the first function as myfunc2(arrayName) . same array can be passed to function even if it is declared as global and also it can be used in other functions but changed done anywhere will effect array elements becos it always works with memory (as pass by refrence)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.