(You're missing a semicolon on the return statement. If you're going to
post code, it's important to copy-and-paste the actual code that you've
compiled. Otherwise minor errors can creep in -- and in some cases such
minor errors can obscure what you're asking about and make it more
difficult for us to help. The missing semicolon is relatively innocuous
and easy to fix; I'll have to assume that's the only error.)
Later, you wrote:
> Thank you. Do I understand correctly that all
> elements should be equal to 0 when the program
> finally runs, thus I get a set of 10 values all equal zero?
That's a question about interpreting the wording of the exercise, not
about C, but I'll try to answer it anyway.
In the existing program, the initial values of the "values" array are
garbage. *Some* of those values are updated by the assignments; others
are left alone. The program then prints all the values, including the
garbage ones. (Strictly speaking this is undefined behavior; in
practice, it will probably just print the garbage values, which may or
may not vary from one execution to the next.)
The problem statement says that the array elements are *initially* set
to zero. I think what this means is that you should:
1. Define the array (that's already done);
2. Use a for loop to set all the array elements to zero;
3. Assign values to some elements (overwriting the zero values you
assigned in step 2) (that's already done); and
4. Print the values of all the elements of the array.
When I run the original program, the output starts with:
values[0] = 97
values[1] = 32542
values[2] = -101
where 32542 is the garbage value that happened to be in memory. You'll
probably see something else. The modified program's output should start
with:
values[0] = 97
values[1] = 0
values[2] = -101
That's my interpretation. You shouldn't take my word for it.
Re-read the problem statement and decide whether it's consistent
with my interpretation.
--
Keith Thompson (The_Other_Keith)
ks...@mib.org <
http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"