posted 10 years ago
In C and C++, an lvalue is anything that can be assigned to; its name comes from anything that can be on the left-hand side of an assignment operator.
Other assignments can involve lvalues implicitly, even though no assignment operator is involved. the ++ operator, for example, assigns a new value to its operand. But the same rules apply:
Your program is violating these rules, hence the error message you get. If we look at the line that's the problem:
we realize that you want to pass a pointer to an integer in the array to scanf() so that scanf() has a place to put the integer it read. Then, you want to increment the pointer so the next time through the loop you have a new place for the next integer.
Problem is, you can't change the "array" variable like that; it's not an lvalue. The way to make your code work would be to get another pointer -- since pointers are lvalues and arrays are not -- and use that, instead. If you initialize that pointer to the first element in the array, you can walk along that array as you expect:
Your function has another serious problem, though: it's returning a pointer to memory that's local to the stack. You'll want to fix that issue, too.