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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:14:07+00:00 2026-06-06T20:14:07+00:00

Does someone know why i never get the first value of my array? it

  • 0

Does someone know why i never get the first value of my array? it always starts at the index i+1, when i start the for loop at 0, or like here at 1 : instead of x=44, the console says x=100 :

//at the top
#define kMaxHillKeyPoints 5

//in the .h:
CGPoint _hillKeyPoints[kMaxHillKeyPoints];

- (void)generatePath {

    int _nVertices = 1;

    _hillKeyPoints[_nVertices] = CGPointMake(44, 0);
    _hillKeyPoints[_nVertices++] = CGPointMake(100, 75);
    _hillKeyPoints[_nVertices++] = CGPointMake(50, 150);
    _hillKeyPoints[_nVertices++] = CGPointMake(150, 225);

    for(int i = 1; i < 4; i++) {   
        CCLOG(@" _hillKeyPoints[1].x : %f", _hillKeyPoints[1].x);
        CCLOG(@"%i", i);
    }
}

//output :
_hillKeyPoints[1].x : 100.000000 //why not x = 44 ?

Would you know why? i cleaned the project also, but it does not change anything.

Thanks

  • 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-06T20:14:09+00:00Added an answer on June 6, 2026 at 8:14 pm

    First, you did the following:

    int _nVertices = 1;
    _hillKeyPoints[_nVertices] = CGPointMake(44, 0); //_nVertices = 1
    

    This assigns _hillKeyPoints[1] to (44,0). Here, you are still good (you can NSLog here to verify).

    However, in the following statement:

    _hillKeyPoints[_nVertices++] = CGPointMake(100, 75);
    

    you are post-incrementing _nVertices. This means that _hillKeyPoints[_nVertices] is first assigned to (100,75), then the value _nVertices is incremented. The statement above is exactly equivalent to doing this:

    _hillKeyPoints[_nVertices] = CGPointMake(100, 75); 
    _nVertices = _nVertices + 1;
    

    Note that _nVertices = 1 here during assignment, so you are overwriting your previous assignment of (44, 0), and hence you get _hillKeyPoints[1] = (100,75) in the end.

    If you still want to do it your way, you can pre-increment the index each time:

    int _nVertices = 1; 
    _hillKeyPoints[_nVertices] = CGPointMake(44, 0); //_nVertices = 1
    _hillKeyPoints[++_nVertices] = CGPointMake(100, 75); //_nVertices = 2
    _hillKeyPoints[++_nVertices] = CGPointMake(50, 150); //_nVertices = 3
    _hillKeyPoints[++_nVertices] = CGPointMake(150, 225); //_nVertices = 4
    

    Hope this helps.

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

Sidebar

Related Questions

does someone know how to draw 3D surfaces and hide the invisible lines? I
Does someone know of a Sqlite manager that I can put on my site,
Does someone know or have an idea of how to reload the contents of
Does someone know why this is not a strict quine ? _0='_0=%r;print _0%%_0';print _0%_0
Does someone know how to write a program in C with the verbose option
In jQuery ajax function there is xhr option. Does someone know more details, usability
This StackOverflow answer has an image of KDiff3 highlighting intra-line differences. Does someone know
Does anyone know what error message will be displayed when someone tries to run
does someone have an idea how to get the environment variables on Google-AppEngine ?
Does someone know what might go wrong, when you attempt to compare two System.Drawing.Image

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.