0

I have the following code:

typedef struct
{
 int a;
 int b;
} Hello;

typedef struct
{
 char c;
 int d;
} World;

Hello hello[10][10];
World world[5];

Then I have the following functions:

void getInfo(Hello hello_p[][10], World* world_p)
{
     // Here I suppose to get the size of pointer to the array of hello and world
     sizeof(hello_p);
     sizeof(world_p);   
}

void getHello(Hello (** hello_p)[10])
{
    hello_p = hello;
}

void getWorld(World ** world_p)
{
    world_p = world;
}

then I call the function like:

Hello (*hello_p)[10]      = NULL;
World *world_p    = NULL;


getHello(&hello_p);
getWorld(&world_p);

getInfo(hello_p, world_p);

then in the getInfo function, can I get the size of the pointer to the array of hello and world?

user2131316
  • 3,111
  • 12
  • 39
  • 53

2 Answers2

1

When an array is passed to a function id decays to a pointer and the size information is lost.

Here you are getting the size of the pointer

 sizeof(hello_p);
 sizeof(world_p);   

You will have to pass an additional argument to the function if you want to have information about its size.

0

Can I get the size of the pointer to the array of hello and world?

The size of a pointer should be the same for any type. So the size of a pointer to Hello* and World* should both be the same as int* (for example).

Shoe
  • 74,840
  • 36
  • 166
  • 272