Question: 1. The following code attempts to create a new variable of type presence( a kind of structure) but when I run it through gdb, it shows that the variable has the same address in every iteration? Shouldn't a local variable get a different address when it is being redeclared?

```
presence* hashtable[MAX];
int i = 0;

printf("---------ENTERING DATA FOR THE HASHTABLE------------------\n");
while (i < MAX)
{

        presence item; /* Same address on every iteration */
        printf("Enter item id : ");
        scanf("%d",&item.id);

        printf("Enter item name : ");
        item.name = (char*)malloc(SIZE*sizeof(char));
        getchar();
        fgets(item.name,SIZE,stdin);

        putItem(hashtable,&item);
        i++;

}

```
2. When a item of type presence is put inside the hashtable, should I allocate the memory and then assign item or do it simply(refer the following code)

```
int putItem(presence* hashtable[], presence* item)
{
    int key = hash(item->id);
    hashtable[key] = (presence*)malloc(sizeof(presence)); /* Required or not? or do the below straight away?*/
    hashtable[key] = item;
}

```

Answer: 
For 1: You should have `presence *item;` pointer type variable, allocate it and use it to fill the data. Your current implementation uses same variable in each iteration.

```
while (i < MAX)
{

        presence *item; /* pointer */
        item = malloc(sizeof(*item));
        printf("Enter item id : ");
        scanf("%d",&item->id);

        printf("Enter item name : ");
        item->name = (char*)malloc(SIZE*sizeof(char));
        getchar();
        fgets(item->name,SIZE,stdin);

        putItem(hashtable,item);
        i++;

}

```

For 2: You don't need to allocate memory. The line

```
hashtable[key] = (presence*)malloc(sizeof(presence));

```

is not needed.

However make sure `key` is less than `MAX` which is size of `hashtable`. Also, you may want to handle clashes appropriately.
Your local variables are volatile. When you create an instance, it disappears when the variable goes out of scope. So, you may get the same address in the following iteration.

In the seconds instance, you do need to `malloc` the space for `presence` and need to copy it using `memcpy`. Instead of using `hashtable[key] = item`, you should do `memcpy ( hashtable[key], item, sizeof ( item ) );`