Weird problem with arduino I wrote the code below and the result is not what I expected at all! I'm not sure why it's happening!
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

const uint8_t pat[] PROGMEM = {
  0xff,
  0x00,
  0xff,
  0x00,
  0xff,
  0x00,
  0xff,
  0x66
};

void loop() {
  delay(100);
  Serial.println(sizeof(pat));
  for (int i=0; i&lt;8; i++){
    Serial.print(pat[int(i)],HEX);
  }
  Serial.println(&quot;&quot;);
  Serial.print(pat[0],HEX);
  Serial.print(pat[1],HEX);
  Serial.print(pat[2],HEX);
  Serial.print(pat[3],HEX);
  Serial.print(pat[4],HEX);
  Serial.print(pat[5],HEX);
  Serial.print(pat[6],HEX);
  Serial.print(pat[7],HEX);
  Serial.println(&quot;&quot;);
  while(true);
}

the output is surprisingly this:

8
008000010
FF0FF0FF0FF66

What is compiler doing in the background but it seems to be messing things up really bad! The loop should be doing the exact same thing as manually writing that code over and over but it's not! How can I fix the loop?
If you want to get a value from PROGMEM you must read it with pgm_read functions. Read the PROGMEM reference.

for (int i = 0; i &lt; 8; i++) {
  Serial.print(pgm_read_byte_near(pat + i),HEX);
}


pat[0] in Serial.print(pat[0],HEX); is an item in a constant array const uint8_t pat[]. it can't change at runtime so the compiler uses the value 0xFF. that is why it is printed ok without pgm_read_byte_near