#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int main()
{
int x = 100, i;
double D[x];
for(i=0; i < 100; i++)
scanf("%f", D++);
return 0;
}
The code has two errors:
"%f"rather then"%lf"- compilation errorD++- compilation error
But why is D++ an error? as D is a pointer to the first element of the array and ++ can be used on an array, like pointers?
Dbecause it is not a pointer. An array can decay to a pointer to its first element, but it's not a pointer in itself. What you probably want is something like&D[i]instead.scanfthe format%fis forfloat.Dreally was a pointer, and you could doD++, then you would lose the original value ofD. Once the loop was over, how would you access the data you just read, if you no longer have a pointer to it?