Comparing one structure variable with another structure variable is illegal in C

C does not allow us to compare one structure variable with another variable


As can be seen from the below example that the structure called student contain two variable that is stud1 and stud1

But in C, it is not possible to compare one structure variable(stud1) with another structure variable (stud2)

Such as

Stud1>stud2 or  Stud1>stud2

Let’s see an example

#include <stdio.h>
struct student
    char name[50];
    int roll_no;
    float fees;
    char course[80];
int main()
    struct student stud1={"one",01,100.0,"history"};
    struct student stud2={"two",02,200.0,"biology"};
        printf("\nThere is a difference between different student fees");
   return 0;



It is important to realize, that you can use an assignment operator on a structure variable


Another key point, you can use equality operators on a structure variable without any problem


But, C does not allow to use of equality comparison on a structure variable


Mohammed Anees

Hey there, welcome to aneescraftsmanship I am Mohammed Anees an independent developer/blogger. I like to share and discuss the craft with others plus the things which I have learned because I believe that through discussion and sharing a new world opens up

Leave a Reply

Your email address will not be published.