Robby
2010-01-17 19:09:01 UTC
Hello,
Okay, I know how to pass an array to a function.... but then not being able
to view the array's contents is not normal.
Please view the sample code at:
http://irc.essex.ac.uk/www.iota-six.co.uk/c/f3_passing_arrays_to_functions.asp
Now, I have modified the code a little and entered it this way... please
view the following code sample:
=================================
#include <stdio.h>
int addNumbers(int fiveNumbers[]);
int main()
{
int y;
int array[5]={1,2,3,4,5};
y = addNumbers(array);
return 0;
}
int addNumbers(int fiveNumbers[])
{
int sum = 0;
int i;
for(i=0 ; i<5 ; i++) {
sum+=fiveNumbers[i];
}
return sum; //<<< BREAKPOINT HERE
}
=============================
When I stop at the breakpoint in the addNumbers() function, the value of sum
does equal 15, which means that the compiler is reading off *all* the correct
values from the fiveNumbers array. But why is it that we can't view the
contents of "fiveNumbers" array in the watch window like this:
fiveNumbers
[0] ... 1
[1] ... 2
[2] ... 3
[3] ... 4
[4] ... 5
All I read in the watch window is:
fiveNumbers
[] ... 1
Okay, I know how to pass an array to a function.... but then not being able
to view the array's contents is not normal.
Please view the sample code at:
http://irc.essex.ac.uk/www.iota-six.co.uk/c/f3_passing_arrays_to_functions.asp
Now, I have modified the code a little and entered it this way... please
view the following code sample:
=================================
#include <stdio.h>
int addNumbers(int fiveNumbers[]);
int main()
{
int y;
int array[5]={1,2,3,4,5};
y = addNumbers(array);
return 0;
}
int addNumbers(int fiveNumbers[])
{
int sum = 0;
int i;
for(i=0 ; i<5 ; i++) {
sum+=fiveNumbers[i];
}
return sum; //<<< BREAKPOINT HERE
}
=============================
When I stop at the breakpoint in the addNumbers() function, the value of sum
does equal 15, which means that the compiler is reading off *all* the correct
values from the fiveNumbers array. But why is it that we can't view the
contents of "fiveNumbers" array in the watch window like this:
fiveNumbers
[0] ... 1
[1] ... 2
[2] ... 3
[3] ... 4
[4] ... 5
All I read in the watch window is:
fiveNumbers
[] ... 1
--
Best regards
Roberto
Best regards
Roberto