Operation on Individual Members of Structures
All operations are valid on individual members of structures.
Example program illustrating operations on structure members:
#include<stdio.h>
#include<string.h>
struct student
{
int rno;
char name[10];
int marks,age;
};
void main()
{
int m;
//assigning values to structure variable s1 using initalization
struct student s1={2,"Gandhi",89,18};
struct student s2;
s2=s1;
printf("\nDetails of student 1:\n");
printf("\n roll number: %d",s1.rno);
printf("\n name :%s",s1.name);
printf("\n marks: %d",s1.marks);
printf("\n age: %d",s1.age);
printf("\n\n");
printf("Details of student 2:\n");
printf("\n roll number: %d",s2.rno);
printf("\n name :%s",s2.name);
printf("\n marks: %d",s2.marks);
printf("\n age: %d",s2.age);
//comparsion of two student details.
m=((s1.rno==s2.rno)&&(s1.marks==s2.marks))?1:0;
if(m==1)
printf("\n both the details are same");
else
printf("\n both the details are not same");
}
Output:
