Pages: [1]   Go Down
Author Topic: Error in an example on http://arduino.cc/en/Reference/Array  (Read 2763 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Dear Webmaster,
I think it might be necessary a correction in the example written in web page http://arduino.cc/en/Reference/Array,
section "Creating (Declaring) an Array":
wrong text:
Code:
int myInts[6];
int myPins[] = {2, 4, 8, 3, 6};
int mySensVals[6] = {2, 4, -8, 3, 2};

proper text:
Code:
int myInts[5];
int myPins[] = {2, 4, 8, 3, 6};
int mySensVals[5] = {2, 4, -8, 3, 2};

I suggested the correction here because "Corrections, suggestions, and new documentation should be posted to the Forum".
« Last Edit: May 01, 2014, 03:12:58 pm by pietrasopra » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 224
Posts: 13917
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No, this is correct C although I agree it not "clean code"
int mySensVals[6] = {2, 4, -8, 3, 2};
initializes the first 5 elements of the array of size 6.
Most compilers will initialize the 6th element with zero iff the arra is declared global.

Check this code.

Code:
int mySensVals[6] = {2, 4, -8, 3, 2};

void setup()
{
  Serial.begin(115200);
  Serial.println("Start ");
 
  for (int i=0; i<6; i++)
  {
    Serial.println(mySensVals[i]);
  }
}

void loop()
{
}
That said, I agree it is not a clean example.
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 637
Posts: 34597
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Why do you think that
Code:
int myInts[6];
should be
Code:
int myInts[5];
As this variable is not referenced anywhere there could be any number in the braces.

Besides which we have bee trying to get the real error of the capacitor on the latch pin in the shift out tutorial, fixed for over 6 years and that is a real error that can cause real harm.
Logged

Pages: [1]   Go Up
Jump to: