Oh I see, I updated my code but idk why the variable C has same memory location as B, when I try to print it on monitor. First I replaced ptr3 = C; and then ptr3 = B; and it showed same memory location address as for both of them, I changed them one by one and uploaded one by one. I didn't compare them by storing those addresses in two different variables. Also When I printed location of array A[0], A[1], A[2], A[3] the result was 200, 202, 204, 206. Then I replaced ptr3 = C; it seemed that as if memory allocation shifted every time. the result was 202, 204, 206 and 200 for "C". Can you please explain and help me why is this happening. Should I understand and learn properly and completely how does memory work before learning pointers?
here's my code:
int A[] = {'h', 'e', 'l', 'l', 'o'};
int B = 4;
int C = 6;
int *ptr;
int *ptr1;
int *ptr2;
int *ptr3;
void setup(){
Serial.begin(115200);
}
void loop(){
ptr = &A[0];
ptr1 = &A[1];
ptr2 = &A[2];
ptr3 = &C;
Serial.print((int) ptr, HEX);
Serial.print(" ");
Serial.print((int)ptr1, HEX);
Serial.print(" ");
Serial.print((int)ptr2, HEX);
Serial.print(" ");
Serial.println((unsigned int)ptr3, HEX);
}