P
Paminu
Still having a few problems with malloc and pointers.
I have made a struct. Now I would like to make a pointer an array with 4
pointers to this struct.
#include <stdlib.h>
#include <stdio.h>
typedef struct _tnode_t {
void *content;
struct _tnode_t *kids;
} tnode_t;
int main(void)
{
tnode_t *array;
array = malloc(sizeof(tnode_t)*4);
array[3] = NULL;
return 0;
}
As I understand "array" point to the first element of an array consisting of
space for 4 tnode_t structs. But why can't I initialize element at index 3
to NULL?
I have made a struct. Now I would like to make a pointer an array with 4
pointers to this struct.
#include <stdlib.h>
#include <stdio.h>
typedef struct _tnode_t {
void *content;
struct _tnode_t *kids;
} tnode_t;
int main(void)
{
tnode_t *array;
array = malloc(sizeof(tnode_t)*4);
array[3] = NULL;
return 0;
}
As I understand "array" point to the first element of an array consisting of
space for 4 tnode_t structs. But why can't I initialize element at index 3
to NULL?