sizeof misbehaving (or I'm misusing it)

Hi, I'm trying to figure out the size of an array (of some struct I created). sizeof function is not working for me.

Here is the struct:

typedef void Handler(String param1, String param2);
struct Resource
  {
    String uri;
    Handler *handler;
  };

Here is the array declaration and population

struct Resource URIs[6];
  URIs[0].uri = "/resourceType1";
  URIs[0].handler = handler1;
  URIs[1].uri = "/resourceType2";
  URIs[1].handler = handler2;
  URIs[2].uri = "/resourceType1/resourceType11";
  URIs[2].handler = handler3;
  URIs[3].uri = "/resourceType1/{:resourceType1Id}";
  URIs[3].handler = handler4;
  URIs[4].uri = "/resourceType1/{:resourceType1Id}/resourceType13";
  URIs[4].handler = handler5;
  URIs[5].uri = "/resourceType1/resourceType12/{:resourceType12Id}";
  URIs[5].handler = handler6;

Serial.print(sizeof URIs); prints "2".

I thought of sizeof URIs / sizeofURIs[0] but it was not the case.

Some help would be appreciated

typedef void Handler(String param1, String param2);

struct Resource
  {
    String uri;
    Handler *handler;
  };

struct Resource URIs[6];

void setup() 
{
  Serial.begin( 115200 );
  Serial.print(sizeof URIs);
}

void loop() {
  // put your main code here, to run repeatedly:

}

Your failure to post all of your code has resulted in my wasting my time and you wasting your time.

What Coding badly said.

Looks like sizeof is reporting the size of a pointer not the array.

An array name is syntactically equivalent to a pointer to the first element of the array. However, when you reference the array variable directly, the compiler knows how big it is and sizeof() tells you the number of bytes occupied by the array. When you access the array indirectly, for example by using an array variable as the argument to a function, within the function we no longer know the size of the array and sizeof() will report the size of a pointer.

You're not alone in being caught out by this.

PeterH has given you the answer. The short program below shows one way to use the sizeof() operator to determine the number of elements in the array:

 #define getElements(x) (sizeof(x) / sizeof(x[0]))

int myArray[11];
float yourArray[5];
byte theirArray[] = {1,2,3,4,5,6};

void setup() { 
  Serial.begin(115200); 
  
  Serial.print("Size of myArray = ");
  Serial.println(getElements(myArray));
  Serial.print("Size of yourArray = ");
  Serial.println(getElements(yourArray));
  Serial.print("Size of theirArray = ");
  Serial.println(getElements(theirArray));
  
} 

void loop() { 
  
}

Essentially, what the preprocessor macro is doing is taking the total number of bytes that are allocated to the array (the first expression in the macro) and dividing it by the size of one element in the array. For example, since each float requires 4 bytes of storage, the compiler has allocated 20 bytes for yourArray[]. The macro expansion becomes:

sizeof(x) / sizeof(x[0])
sizeof(yourArray) / sizeof(float))
20 / 4
5

So there are 5 elements in the array. Another nice feature of using the macro is that it’s portable. If you moved this code to a machine that uses 4 byte integers, it still correctly calculates the number of elements.