Hello,
gcc 4.4.4 c89
I am just wondering why I am getting different memory address. When I print the address of animals in main I get the following:
animals [ rabbit ] : [ 0xbfab2e48 ]
animals [ rabbit ] : [ 0xbfab2e48 ]
However, when I print in the function, I get different memory locations. I think they should be the same.
ptr animals [ rabbit ] : [ 0xbfab2e08 ]
ptr animals [ rabbit ] : [ 0xbfab2e08 ]
Many thanks for any advice,
int main(void)
{
char *animals[] = {"rabbit", "cat", "dog", "elephant", "racoon", NULL};
char *countries[] = {"india", "amercia", "france", "spain", "canada", "mexico", NULL};
char *cars[] = {"ford fista", "Masda 3", "honda city", "toyata cote", NULL};
char **ptr_data[] = {animals, countries, cars, NULL};
printf("animals [ %s ] : [ %p ]\n", *animals, (void*)animals);
printf("animals [ %s ] : [ %p ]\n", animals[0], &animals[0]);
print_data_ptr(ptr_data);
return 0;
}
void print_data_ptr(char ***ptr)
{
char **data_list = NULL;
printf("ptr animals [ %s ] : [ %p ]\n", *ptr[0], (void*)&ptr[0]);
printf("ptr animals [ %s ] : [ %p ]\n", **ptr, (void*)ptr);
}