Declaring simple struct:
struct s {
char* addr;
};
s *ips;
Now allocating that struct array memory
num = 5
ips = (r *) malloc(num * sizeof(r));
I know malloc just allocates memory, and don't initialize, there could be garbage values.
Now I wonder if I don't initialize one, and try to access what would happen?
//Init for 4 of them
for(int i = 0; i < num-1; i++)
ips[i].addr = strdup("123");
//Accessing un-initialize one:
if(ips[4].addr) {
printf("Accessing uninitialize one and lets say freeing!!!");
free(ips[4].addr);
}
Ideal should not be going into this for loop. But then I think because of garbage value it may be. I'm not sure!