#include <stdio.h>
struct invent
{
char name[20];
int number;
float price;
};
int main()
{
char ch;
struct invent product[3],*ptr;
printf("INPUT\n\n");
for(ptr=product;ptr<product+3;ptr++)
scanf("%s %d %f",ptr->name,&ptr->number,&ptr->price);
printf("\nOUTPUT\n\n");
ptr=product;
while(ptr<product+3)
{
printf("%20s %5d %10.2f\n",ptr->name,ptr->number,ptr->price);
ptr++;
}
return 0;
}
Why in scanf function for entering name only ptr->name is used while entering number and price &ptr->number, &ptr->price is used. I want to ask why we are using & at all because ptr is itself storing the address of structure. Here is another code to explain
int main()
{
int a,*p;
p=&a;
scanf("%d",p);
printf("%d",a);
return 0;
}
In the above code we are not using &p in scanf function because p is itself storing the address of a, so why use &ptr->number and &ptr->price for structures.