Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

pointer

Status
Not open for further replies.

thelearner

Programmer
Jan 10, 2004
153
US
Hi,

Here is my program snippet. It suppose to set the entire array to 37.0. But why does it show 0 when I output the 1st 2 elements. Is something wrong on my printf statements?

Thanks in advance.


float values[100];
float *pt3;
int ii;
pt3 = values;

for (ii = 0; ii < 10; ii++)
{
*pt3++ = 37.0;
printf("value[0] = %d\n", values[0]);
printf("value[1] = %d\n", values[1]);

}


 
printf("value[0] = %f\n", values[0]);
printf("value[1] = %f\n", values[1]);

Replace the %d with %f
 
>>It suppose to set the entire array to 37.0.
But you're only looping 10 times, when the array is 100 elements long?!

Also, the first time through the loop, the value of values[1] is undefined, as you haven't yet assigned it one.
 
I know Hammer. I make it loop just 10 times just to see some sample result.
>> the first time through the loop, the value of values[1] is undefined<<
I just want to compare between 1st and 2nd elements so I have an idea what's going on.Thanks any way.
I changing to %f as cdlvj point out and it's ok now.

Thanks for all responses.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top