Page 97 - 6437
P. 97
printf( "Array values using pointer\n");
for ( i = 0; i < 5; i++ )
{
printf("*(p + %d) : %f\n", i, *(p + i) );
}
printf( "Array values using balance as address\n");
for ( i = 0; i < 5; i++ )
{
printf("*(balance + %d) : %f\n", i, *(balance + i) );
}
return 0;
}
When the above code is compiled and executed, it produces the following result:
Array values using pointer
+ 1000.0
(p 0) : 00000
+ 2.0000
(p 1) : 00
+ 3.4000
(p 2) : 00
+ 17.000
Array values using balance as address
3) : 000
(p
+ 50.000
(p 4) : 000
*(ba + 1000.0
lance 0) : 00000
*(ba + 2.0000
lance 1) : 00
*(ba + 3.4000
lance 2) : 00
*(ba + 17.000
lance 3) : 000
*(ba + 50.000
lance 4) : 000
In the above example, p is a pointer to double, which means it can store the address of a
variable of double type. Once we have the address in p, *p will give us the value available at the
address stored in p, as we have shown in the above example.
10
0