I am writing a program that asks the user to enter the expenses for each
season of the year, and then sum the expenses. The thing is, I have to do it by passing a structure with single array to the functions. I don't know why but for some reason I got error like this : error C4700: uninitialized local variable 'year' used.
I think that I've declared everything well.
I am using Visual Studio 2013, here is my code:
Line 24: You're passing expenses by value, but the object has not been initialized yet. The intent of your function is to fill in expenses, so you want to pass expenses by reference, not value. You want to operate on the call's struct, not a local copy that goes out of scope when fill exits.
You are passing a copy of an uninitialized variable to a function. The only reason to do that is if the function is going to use the values contained in the variable. It wouldn't make sense to pass a variable by value if you were going to modify it. So, your compiler is letting you know something is off (and it is -- fill should take its first argument by reference.)
Thank you, now it works fine, but I don't get why can I pass an array without errors like that?
Is it because I am not really passing an array value to the function but the address of its first element? What if I tried to pass just the array from my structure by value? Should it work fine then? Your comments were really helpful so far.