Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6088259
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:57:52+00:00 2026-05-23T11:57:52+00:00

Why whole structure can not be compared in C yet it can be copied?

  • 0

Why whole structure can not be compared in C yet it can be copied?
In other words, Why comparison in below program does not work? It does not print string.

#include <stdio.h>
#include <string.h>

int main(void)
{

    struct emp
    {
        char n[20];
        int age;
        };

    struct emp e1={"David",23};
    struct emp e2=e1;
    if(e2 == e1)
    {
        printf("The structures are equal");
    }
    return(0);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:57:53+00:00Added an answer on May 23, 2026 at 11:57 am

    You could use memcmp(). That’s not a good idea in general though, structures tend to have padding bytes between the fields. The padding is used to align the field. Your structure doesn’t have any but that’s by accident. That padding can have any kind of value, making memcmp() fail to work because it sees all the bytes, not just the ones in the fields.

    There’s more, you have a C string in the structure. It can contain any kind of bytes past the zero terminator. Using strcmp() on the strings would return 0 but memcmp() again fails because it sees all the bytes. Pointers would be yet another failure mode.

    Compare one field at a time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I tell boost that for a particular structure it should not write/read
I've been working with Swing for a while now but the whole model/structure of
I'm using a huge binary tree like structure whose nodes may or may not
I've spent whole days with PHP's DOM functions but i can't understand how it
This url structure is proposed for SEO optimization. So suggesting another structure will not
Can I get the whole query which I used for creating a table, like
I'm trying to graph the linking structure of a web site so I can
Need: Ability to dynamically build Forms Structure (simple idea not actual structure) Admin: Form
How can I achieve the following structure without using tables or JavaScript? The white
I tried passing a structure as the 4th argument while using pthread_create() with something

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.