I appreciate that you're trying to figure out the syntax, but I suggest that you don't do things that way. Let's look at your print loop:
Code:
for(i =0; i < num;++i)
printf("%s\t%d\t%.2f\n",(ptr+i)->name,(ptr+i)->age,(ptr+i)->weight);
This is fine, but because you are iterating by index, we would more commonly use array index syntax:
Code:
for (i = 0; i < num; ++i)
printf("%s\t%d\t%.2f\n", ptr[i].name, ptr[i].age, ptr[i].weight);
As you can see, this makes it a bit easier to reason: ptr[i] is the "current element" in each iteration.
If you want to use pointer syntax, then work with pointers, e.g.,
Code:
struct person *end;
for (end = ptr + num; ptr != end; ++ptr)
printf("%s\t%d\t%.2f\n", ptr->name, ptr->age, ptr->weight);
As you can see, by iterating with a pointer instead of an index, we don't need to do pointer arithmetic beyond incrementing the pointer, as long as we aren't say, trying to access other elements in the array via the pointer. This is because now ptr is the "pointer to the current element" in each iteration.
So, back to your question. It looks like &(ptr+i)->name is actually wrong. It should indeed have been just (ptr+i)->name. Again, if you had used array index notation to match your iteration by index:
Code:
for (i = 0; i < num; ++i)
{
printf("Enter name, age and weight of the person respectively:\n");
scanf("%s%d%f", ptr[i].name, &ptr[i].age, &ptr[i].weight);
}
whereas if you actually want to work with pointers proper:
Code:
struct person *end;
for (end = ptr + num; ptr != end; ++ptr)
{
printf("Enter name, age and weight of the person respectively:\n");
scanf("%s%d%f", ptr->name, &ptr->age, &ptr->weight);
}
By the way, you should check the return value of scanf to see if the read was successful.