#include <stdio.h>
struct Person
{
char name[50];
int roll;
float marks;
} s[5];
int main()
{
printf("Enter information of students:\n");
for (int i = 0; i < 5; ++i)
{
s[i].roll = i + 1;
printf("\nFor roll number %d,\n", s[i].roll);
printf("Enter name: ");
scanf("%s", s[i].name);
printf("Enter marks: ");
scanf("%f", &s[i].marks);
}
printf("\nDisplaying Information:\n");
for (int i = 0; i < 5; ++i)
{
printf("\nRoll number: %d\n", s[i].roll);
printf("Name: ");
printf("%s\n", s[i].name);
printf("Marks: %.1f\n", s[i].marks);
}
return 0;
}
I am learning C programming from the website, however I don't understand why does scanf
with name we don't need &
in front of s[i].name
, while s[i].marks
there is a &
before.
Hope the question is clear, and thank you for reading my post.
(https://www.programiz.com/c-programming/examples/information-structure-array)