Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » BeginnersRSS Feeds

Comparing and copying structure variables

Posted By: Mina Schmidt     Category: C Programming     Views: 5781

Comparing and copying structure variables.

Code for Comparing and copying structure variables in C Programming

structclass                                                     
   {
       int  number;                                                 
       char name[20];                                               
       float marks;                                                 
   };                                                               
                                                                    
   main()                                                           
   {
       int  x;                                                      
       structclass student1 = {111,"Rao",72.50};            
       structclass student2 = {222,"Reddy", 67.00};         
       structclass student3;                                       
                                                                    
       student3 = student2;                                         
                                                                    
       x = ((student3.number ==  student2.number) &&                
            (student3.marks  ==  student2.marks)) ? 1 : 0;          
                                                                    
       if(x == 1)                                                   
      {
            printf("\nstudent2 and student3 are same\n\n");          
           printf("%d %s %f\n", student3.number,                    
                                student3.name,                      
                                student3.marks);                    
       }                                                            
       else                                                         
           printf("\nstudent2 and student3 are different\n\n");     
                                                                    
   }                                                                
                                                                    
Output                                                           
                                                                    
   student2 and student3 are same                                   
                                                                    
   222 Reddy 67.000000                                              
  
Share: 


Didn't find what you were looking for? Find more on Comparing and copying structure variables Or get search suggestion and latest updates.

Mina Schmidt
Mina Schmidt author of Comparing and copying structure variables is from Frankfurt, Germany.
 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!