Variable passed to Printin

I am trying to find how to pass a value stored in a variable into a Printin statement.

Is this correct or is there a better way.

int MyValue = 0;
MyValue = 1000;

Serial.println(MyValue);

Also can I use MyValue(2) = 1000. This in attempt to have an array where values could be extracted in a loop. If correct, then how do I declare such an array.

Thanks

is there a better way.

That depends on what you are trying to do

int MyValue = 0;

Declares a new variable named MyValue and initialises its value to 0

MyValue = 1000;

Changes the contents of the MyValue variable to 1000 as long as it has already been declared in the current scope.

You could use

int MyValue = 1000;

to declare and initialise the variable if it has not previously been declared in the current scope

Arrays in C use levels in square brackets so

MyValue[2] = 1000;

would be valid as long as the variable had previously been declared as having 3 levels as in

int MyValue[3];

Note that C array indices start from zero

It's not "printin", it's "println" - the letter after the 't' is a lowercase 'L'.

Also can I use MyValue(2) = 1000.

An array has square braces

int array [2] = {100, 1000};

Many thanks all, that helps me very much. Have a good weekend

int array [2] = {100, 1000};

initialises a 2 element array but note that subsequently using

array[2] = 1000;

would use memory not allocated to the array because of indexing starting at zero.

Thanks. Problem is my brain is working with basic.

I want to decare a variable either as singular value or many. Thenking MyValue(4) meand I can put 4 individual values in MyValue(1)=50 etc.

Then later getting it out either in a 1-4 loop or saying x = MyValue(3), or MyValue(3)=200

I tried this in both singular and array but sticks on printIn.

void setup() {
 
Serial.begin(9600); 
int MyValue = 0;
MyValue = 1000;

}

void loop() {
  
Serial.println(MyValue);
}

Sorry for being thick.

Just found this code, with works for a single value int.

If I can establish an array version where I can insert singular values of an array then I'm home.

eg Serial.println(MyValue(3));

Also, the Arduino information page shows printin as syntax!

int anArray[4];  //declare an array of 4 ints

void setup()
{
  anArray[0] = 10;  //assign values to the array - could be done when declared
  anArray[1] = 11;
  anArray[2] = 12;
  anArray[3] = 13;

  Serial.begin(115200);
  for (int x = 0; x < 4; x++)  //read the array values starting at index 0
  {
    Serial.println(anArray[x]);  //print the current value
  }
}

void loop()
{
}

www.asciitable.com to see the values of the Printable (i.e. viewable) characters

Or use
char anArray[4];
with 'a', 'b', '0', '1', etc.

It's not printin, it's println, short for print line.

Many thanks outsider. I was told earlier my spelling was wrong, being told it was an L but still looked like an I. Will now remember and use that so thanks.

Thanks very much UKHeliBob, exactly what I wanted. And thanks CrossRoads for the extra bit. Not forgetting AWOL.

Regards all