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 5940711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:00:24+00:00 2026-05-22T16:00:24+00:00

This may be a very basic question but somehow it got me tricked… when

  • 0

This may be a very basic question but somehow it got me tricked… when I write test code, it seems to work, but something is going wrong in production.

// Header file
#define length 100
typedef struct testStr_t {
    int a;
    char b;
    char t1[length];
    char t2[length];
} test;

void populateTest(test*);

// source file
test test1;
test test2;
populateTest(&test1);
test2 = test1;

Will test2 be a deep copy of test1? Or are there gotchas here? Does it matter if the code is compiled with a C compiler or a C++ compiler?

  • 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-22T16:00:25+00:00Added an answer on May 22, 2026 at 4:00 pm

    Deep copies are only hindered by pointers, so your struct will be copied correctly in C. It’ll work in C++ as well unless you define your own operator= that doesn’t copy correctly. You only need to define operator= for types with pointers, since a shallow copy of a pointer will copy the pointer but share the data.

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

Sidebar

Related Questions

This may seem like a very basic question but I did not seem to
This may be a very noobie question, but in today's world of web app
This may be a basic question but how can I include a module with
This may be a very simple problem, but I couldn't find an answer googleing
This may seem like a daft question, but i was wondering about how to
I think this is a very simple question, but I’m new to programming so
This question may seem trivial, but I hope you won't ignore it. Before destroying
This may be a stupid question but however I searched in google with jquery
I know this is not a very technical question, but it's for all technical
This is probably very basic, but it's giving me a headache, and I'm not

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.