im getting the error when compiling the code...
Code:float array[20]; int last; array[last[array]]; how to get red of this
im getting the error when compiling the code...
Code:float array[20]; int last; array[last[array]]; how to get red of this
You have
In general,if you are sure you want something like this,imagine it with numbers and arrays.It would be something like thisCode:array[last[array]];
if you want to access the index described by the last element of the array.Code:array[array[19]]
So maybe you want to say
Code:array[array[last]]
still the same error,i think may be its due to types of the integer variable and float arrays
Have you initialized variable last? Can you please post the code you complied?
im just checking the syntax errors
i have initialised int last = n-1;
int *l ;
l = &last;
What is n?Where is the array you were talking about? :P
Just post all the code you have (i consider it is small from what you say )
Also it would be very kind of you if you could wrap your code in code tags.It is easy
[key]/*Your code here*/[/key] Replace key with code in order this to work.
EDIT : it is ok to say
Code:int a=5; int* p; p=&a;
Last edited by std10093; 11-06-2012 at 05:17 AM.
Yes it is.
Arrays can only be indexed using values that have integral type (char, int, long, unsigned, etc). They cannot be indexed using non-integral values (float as in your case, struct types, etc).
There is also an obscure corner of C that causes "array[index]" and "index[array]" to be equivalent (assuming array is (well....) an array or a pointer, and index has integral type). Because of that, your expression "array[last[array]]" is equivalent to "array[array[last]]" which attempts to use array[last] as an index. In your code, array[last] is of type float so is not a valid index. Hence the compiler error.
What i thought you wanted to do
grumpy is more experienced,so he is sure to have it better in his mindCode:#include <stdio.h> int main( int argc, char *argv[]) { float array[5]; int last = 4; array[0]=1.2; array[1]=1.3; array[2]=1.4; array[3]=1.5; array[4]=1.9; printf("%f\n",array[last]); return(0); }
You get rid of the error by fixing or removing the nonsense code.
Explain what you really want to do and we'll show you how to write code for it that makes sense.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"