Hey guys long time since i've been posting something around here (not.)
So I got to the chapter on how Arrays and Pointers can work together and I want to try my skills as a beginner to code a program.
THE TARGET OF THE PROGRAM:
Set an Array (a[10]) and a Pointer to that array (*pa) and code a loop (for( ; ; loop) that will advance that pointer (*pa) and will set a new content into it with each loop. that means that in the end of the day, my program will automatically set content to each cell of the array by promoting the pointer by 1 and add the sum to that pointer.
THE PROBLEM:
When I run the program it prints the address of the cells instead the value of it.
THE CODE:
Code:
#include <stdio.h>
void main()
{
float a[11], *pa; // Array and ptr set.
int i; // counter for the loop.
pa = a;
for (i=0 ; i<=10 ; i++) // the loop itself.
{
*pa = 50*1.5;
/* %d stands for the number of the counter
for order. %f = pa[i], well... you got it :) */
printf("#%d equals to: #%-15.2f#\n", i, pa[i]);
/*advance the pointer pa (which is pa[0] atm) by 1
to add value to the next in the array order. */
pa++;
}
putchar('\n');
}