Ok so im having some trouble with this pointers ezample i was doing. So before the code somewhat worked (value and *pointer[1] prints 1 and 2 but &pointer[2] prints some numbers). now however, its not printing at all. if i delete everything in the main loop and just tell it to print something, it will do it. but with the current code in the main loop, it dont print anything. Whats wrong?
int value;
int *pointer[]={}; //*pointer = value, pointer = address
int *pointer1;
void setup(){
Serial.begin(115200);
}
void anotherFuntion(){
int x = 1;
int y = 2;
int z = 3;
pointer1 = &x;
pointer[1] =&y;
pointer[2]= &z;
}
void loop() {
anotherFuntion();
value = *pointer1;
Serial.print(value);
Serial.print(" ");
Serial.print(*pointer[1]);
Serial.print(" ");
Serial.println(*pointer[2]);
delay(1);
}
masterfo:
Whats wrong?
All usages of pointer (since it is an array with zero elements) and
taking addresses of non-static local variables to be used outside the function.
Whandall:
All usages of pointer (since it is an array with zero elements) and
taking addresses of non-static local variables to be used outside the function.
I have absolute no clue what u just said 
Kind of the same goes for the code you wrote 
For example
pointer[2]= &z
But pointer is an array of size 0... So you're writing out of scope.
//int value; //no need for this to be global
//but if we want to use x, y, z we need to define them ;)
int x = 5;
int y = 6;
int z = 7;
int *pointers[];
void setup(){
Serial.begin(115200);
}
void anotherFuntion(){
int x = 1;
int y = 2;
int z = 3;
pointers[0] = &x;
pointers[1] =&y;
pointers[2]= &z;
}
void loop() {
anotherFuntion();
int value = *pointer[0];
Serial.print(value);
Serial.print(" ");
Serial.print(*pointers[1]);
Serial.print(" ");
Serial.println(*pointers[2]);
delay(1000); //now we can actually see it
}
Ahh, I see even more crap now... X, y and z can't be local varaibles! They go out of scope after the function ends so any pointer to it is invallid after that!
//int value; //no need for this to be global
//but if we want to use x, y, z we need to define them ;)
int x = 5;
int y = 6;
int z = 7;
int *pointers[];
void setup(){
Serial.begin(115200);
}
void anotherFuntion(){
pointers[0] = &x;
pointers[1] =&y;
pointers[2]= &z;
}
void loop() {
anotherFuntion();
int value = *pointer[0];
Serial.print(value);
Serial.print(" ");
Serial.print(*pointers[1]);
Serial.print(" ");
Serial.println(*pointers[2]);
delay(1000); //now we can actually see it
}
if you want better help along the way turn your compiler's verbose mode on:
warning: array subscript is above array bounds [-Warray-bounds]
pointer[1] =&y;
^
some compilers won't allow this at all:
int *pointer[]={}; //*pointer = value, pointer = address
what is that comment meant to mean?
sterretje:
Out of bounds?
Yeah, that would have been the word 
BulldogLowell:
what is that comment meant to mean?
Although not very sensible in a real product, but in a test sketch it is. A little reminder how a pointer works and that you need to dereference it to use the value pointed at 
Ok thanks guys i think i got it. So bacially the stuff thats going into the pointer (the x,y,z variables) are suppost to be global variables. but i dont understand why is putting those variables inside a fundtion make it go out of bound? in the loop, im calling a void function, so why sould it matter
masterfo:
So bacially the stuff thats going into the pointer (the x,y,z variables) are suppost to be global variables.
No, they need to stay in scope. And yeah, globals stay in scope all the time. But for them you can also just access them if they are always the same.
masterfo:
but i dont understand why is putting those variables inside a fundtion make it go out of bound?
Have a look at scope
Basically, all variables created in a function are deleted / cleaned up when the function ends because the idea is "party over" => "clean up the mess"
It's not the scope (where can you see objects), it's the mere existance of the objects.
After return of a function its automatic variables don't exist any more,
so pointers to the memory locations are no more valid.
Taking addresses of local (scope) static (existance) variables is perfectly valid.
masterfo:
...i dont understand why is putting those variables inside a fundtion make it go out of bound? ...
you have declared an array of zero elements and you then try to access element one and element two.
int *pointer[]={}; //*pointer = value, pointer = address
int *otherThing[2]={};
void setup()
{
Serial.begin(9600);
Serial.println(sizeof(pointer));
Serial.println(sizeof(otherThing)); // pointers are two bytes
}
void loop() {
// put your main code here, to run repeatedly:
}