i started learning C today, and i have some questions about accessing a pointer data.
I have this function in C:
typedef struct
{
size_t size;
size_t usedSize;
char *array;
} charList;
void addToCharList(charList *list, char *data)
{
if(list->usedSize == list->size)
{
list->size *= 2;
list->array = realloc(list->array, list->size * sizeof(int));
}
list->array[list->usedSize++] = *data;
printf("1: %d\n", *data);
printf("2: %s\n", data);
printf("3: %p\n", &data);
}
I use it to create a "auto growing" array of chars, it works, but i'm not understanding why i need to attribute the value "*data" to my array. I did some tests, printing the different ways i tried to access the variable "data", and i had this outputs (I tested it with the string "test"):
1: 116
2: test
3: 0x7fff0e0baac0
1: Accessing the pointer (i think it's the pointer) gives me a number, that i don't know what is.
2: Just accessing the variable gives me the actual value of the string.
3: Accessing it using the "&" gets the memory location/address.
When i'm attributing the value of my array, i can only pass the pointer, why is that? Shouldn't i be attributing the actual value? Like in the second access.
And what is this number that gives me when i access the pointer? (First access)