Navigation

Sunday 21 October 2018

Why can't pointer to float be assigned to another pointer to float in C language?

#include <stdio.h>
void print(float *p, int n); 
int main(void)
{
    float rootbeer[10];
    float things[10][5];

    things[5] = rootbeer;
    return 0;
}
Look at the above C code snippet.
rootbeer is pointer to a floating number.
things[5] is the same as things[5] + 0, which is also pointer to a floating number.
So in my view, rootbeer can be assigned to things[5].
I anticipated it should be able to be compiled successfully.
However, after gcc -std=c11 test.c
I got the error message as below:
test.c: In function ‘main’:
test.c:9:12: error: incompatible types when assigning to type ‘float[5]’ from type ‘float *’
  things[5] = rootbeer;
Why can't pointer to float be assigned to another pointer to float ?


https://stackoverflow.com/questions/3601602/what-are-rvalues-lvalues-xvalues-glvalues-and-prvalues

No comments:

Post a Comment