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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:07:13+00:00 2026-05-13T16:07:13+00:00

I just made my first steps moving into Objective-C . I have a very

  • 0

I just made my first steps moving into Objective-C. I have a very simple question about how arrays works.

I have two .m files:

1)

Line = origin[6];
forloop(i...i++) {
    origin[i]=7;
}
[buildSubview:origin];

2)

Line response[6]; 

-(id)buildSubview:(Line[])origin {
    *response=*origin;
    NSLog(@"response[1]=%o",response[1]);
    NSLog(@"origin[1]=%o",origin[1]);
    ........
    .....
}

The output I get is:

response[1]=0; <-- I would expect the same value as origin
origin[1]=7;

But if I ask to print the value at index 0 I get what I expected:

response[0]=7; <-- Now they are the same
origin[0]=7;

I am asking why two different values ? And also, why if I write

response=origin;

I get an incompatible assignment compile error?

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

    Briefly, sometimes, the name of an array in C “decays” to a pointer to the first element of the array, and that is causing you trouble.

    When you write

    response=origin;
    

    The name origin on the RHS “decays” to be of type Line *, and points to the first element of origin array, whereas response is of type “array [6] of Line”. Since the two types are not compatible (it doesn’t make sense to initialize an array with a pointer), it is an error.

    Now,

    *response=*origin;
    

    doesn’t copy all the memory in origin to response. As I mentioned above, and in more detail in the link above, origin points to the first element of the origin array in this context, so *origin is actually the first element of the array. Therefore, *response=*origin; just copies the value of the first element of the origin array to the first element of response. Since you haven’t assigned a value to response[1], it contains garbage.

    If you want to copy the array data over, you can do a loop:

    size_t i;
    for (i=0; i < 6; ++i)
        response[i] = origin[i];
    

    Or, you can use memcpy():

    memcpy(response, origin, sizeof response);
    

    (The above is for C, Objective-C may have differences and other ways of doing what you want to do.)

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

Sidebar

Related Questions

I have made a new windows service which works fine using barebone code (just
I just installed Ubuntu 8.04 and Eclipse. I made a very simple Hello World
I have a package that I just made and I have an old-mode that
I made a discovery some time back. Just follow these steps: Create a .doc/.xls/.ppt
I have just ported several of our home-made Outlook COM-addins from Delphi 2007 to
First of all this is all just concept, I have no actual programming done
I have just done what appears to be a common newbie mistake : First
We've got a fairly large amount of code that just made the jump to
I just wonder if anyone knows or made a wrapper around Active Directory to
I just got handed an SDK made of C++ dll, lib, exe, and various

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.