The second if statement in main does not print out. If I put just one of the if statements they do execute, but for some reason putting them after each other causes the second if statement to not print anything. Can anyone explain why this happens?
#include <stdio.h>
#include <stdlib.h>
typedef struct entry {
int value;
char *key;
int type;
} entry;
entry* array[5];
void init_arr(){
for(int i=0; i<5; i++){
array[i] = NULL;
}
entry new;
new.value = 2;
new.key = NULL;
new.type = 5;
array[3]= &new;
}
int main(){
init_arr();
if(array[3]->value == 2){
printf("ok\n");
}
if(array[3]->key == NULL){
printf("ok 2\n");
}
return 0;
}```
ok 2entry array[5];(an array ofentrystructs) rather thanentry* array[5];(an array ofentrypointers)... that would have made the whole thing much easier... but if you want pointers, than you really don't want to to initialize the same pointer with stack memory (array[3]= &new)