Knowledge Walls
Venkatesan
Hyderabad, Andhra Pradesh, India
Passcode:
Introduction [cont'd]
Input Output Functions [cont'd]
Structures and Unions [cont'd]
# Preprocessor [cont'd]
Comparing two Structures in Structures and Unions of Programming in C
12370 Views
Comparing two Structures 
Comparing structures in c is not permitted to check or compare directly with logical operators. Only structure members can be comparable with logical operator.

Like
struc_object_1.age == struc_object_2.age
Program
	#include
	struct student {
	   int rno;
	   char name[20];
	   int percentage;
	};
	void main(){
	   //compare structure via members
	   struct student stu1 = {1001,"Ramesh",87};
	   struct student stu2 = {1002,"Arun",85};
	    if (stu1.percentage < stu2.percentage){
	       printf("%s has higher marks.",stu2.name);
	   }
	   else {
	       printf("%s has higher marks.",stu1.name);
	   }
	}
Output 
Ramesh has higher marks.
Next Topics
Next lessons of current book.
Structures and Unions of Programming in C
Structures and Unions of Programming in C
Structures and Unions of Programming in C
Structures and Unions of Programming in C
Previous Topics
Previous lessons of current book.
Structures and Unions of Programming in C
Structures and Unions of Programming in C
User-defined Functions of Programming in C
User-defined Functions of Programming in C
User-defined Functions of Programming in C
Best Lessons of "Programming in C"
Top lessons which are viewed more times.
Structures and Unions of Programming in C
Input Output Functions of Programming in C
Structures and Unions of Programming in C
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details