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

  • SEARCH
  • Home
  • 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 8740185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:05:13+00:00 2026-06-13T11:05:13+00:00

Here is my code. int main() { struct emp { char *n; int age;

  • 0

Here is my code.

int main()
{
struct emp
{
    char *n;
    int age;
};
struct emp e1 = {"Dravid", 23};
struct emp e2 = e1;
strupr(e2.n);
printf("%s\n", e1.n);
return 0;
}

Question 1: The answer as per the website is ‘DRAVID’ that is upper case. Howcome, are e2 and e1 same? i.e. if I do, e2.age++ then will this change be reflected in e1 too?

Question 2: If I change the strupr to strcpy I get seg fault? Why? i.e. If i change it to strcpy(e2.n,"hoho");.

  • 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-06-13T11:05:14+00:00Added an answer on June 13, 2026 at 11:05 am

    After you construct your two emps, this is what you have in memory:

    e1.age  = 23
    e1.name = 0x12345678 (Which is a pointer in memory to "Dravid")
    e2.age  = 23
    e2.name = 0x12345678 (Which is a pointer in memory to "Dravid")
    

    Now notes, on what you’re trying to do.

    1. Calling strupr(e1.name) is undefined behavior, because you’re not allowed to modify string literals.
    2. Calling strcpy(e1.name, e2.name) is also undefined behavior, because strcpy requires that the two pointers passed to it refer to different pieces of memory. Also, its UB because you can’t modify string literals.
    3. Calling strcpy(e1.name, "hiho") is also undefined behavior, because you can’t modify string literals.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my code: struct Point { int i; int j; }; int main(int
Here is the code in question #include <stdio.h> struct test { unsigned char t;
I'm trying to write a video using opencv's VideoWriter. Here's code: int main() {
I got an EXC_BAD_ACCESS in main() , here is my code: int main(int argc,
Here is my code: #include <stdio.h> int main(void) { FILE *fp; unsigned int i;
Here's my code so far: #include<iostream> #include<string> #include<fstream> using namespace std; int main() {
This following code works fine: #include <stdio.h> #include <stdlib.h> int main() { struct node{
Neither of these snippets of code work: int main() { struct mystruct { int
Here is the code #include<stdio.h> #include<sys/types.h> #include<stdlib.h> #include<pthread.h> typedef struct std_thread { char name[20];
Here is my code: struct queue { int queue_arr[5]; int rear; int front; };

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.