When I do something like this in a method:
int a = 2;
if(variabel == a) {
...
}
it works, but Not when using arrays like this:
int *a = {1,2,3};
if(variabel == a[1]) {
.....
}
it just doesnt work in any way...anything special I need to know about arrays??
Arrays
Re:Arrays
if you dont need to change the array you should be able to do something likeArrow wrote: int *a = {1,2,3};
Code: Select all
int a[] = {1,2,3};
Re:Arrays
int *a is not an array of integers, but a pointer to one integer. Your compiler should give you at least a warning about this; GCC sure does.Arrow wrote: int *a = {1,2,3};
if(variabel == a[1]) {
.....
}
Correct is:
Code: Select all
int a[] = {1,2,3};
Every good solution is obvious once you've found it.