By doing
memset(lookup, 0, 100 * sizeof *lookup);
you do not "initialize a pointer" but the memory the pointer lookup points to.
And most probably you did not made the pointer point to some valid memory, prior to calling memset(), so writing to random memory invokes undefined behaviour, which crashes the program.
There are several way to get valid memory.
Get it from the stack like so:
bool lookup_instance[100] = {0};
bool (*lookup)[100] = &lookup_instance;
/* No need to memset it to 0s as this had been done by ... = {0} already. */
or get it yourself like so:
bool (*lookup)[100] = malloc(sizeof *lookup);
if (NULL == lookup)
{
perror("malloc() failed"):
}
else
{
memset(lookup, 0, sizeof *lookup);
}
The shortest solution would be:
bool (*lookup)[100] = calloc(1, sizeof *lookup);
if (NULL == lookup)
{
perror("calloc() failed");
}
else
{
/* No need to memset it to 0s as this has been done by calloc() already. */
}
memsetlikes pointers just fine; and if you were invoking it on the memory occupied by the pointer,memset(&loopkup, 0, sizeof(lookup));the code would be valid (albeit somewhat pointless). As written, you're invoking it with an indeterminate address retrieved from an uninitialized pointer variable, and this is therefore undefined behavior.memsetmust be consistent with the object the pointer points to. The posted code has undefined behavior because the pointer is uninitialized, otherwise post the code that initializes the pointer.