What value will the it return?


if address value in array doesn't exist, value return?

e.g. int number[4] = {1, 2, 3, 4,}

int val = number[4];

/me

it return contents of next 2 adresses in ram

quote



void printvariable(char* name, int& x){
 serial.print(name);
 serial.print(" - value: ");
 serial.print(x);
 serial.print(", @ adress: ");
 serial.println((int)&x);
}

void setup(){
 
 int intvar = -4;
 int intarray[4] = {1,2,3,4};
 int intarray2[5] = {-5,0,0,0,0};
 
 serial.begin(9600);
 
 serial.println("the values , adresses of intarray:");
 for( byte i=0; i<4; i++){
   serial.print(i,dec);
   serial.print(": ");
   printvariable("intarray", intarray );
 }
 
 //the below print identical values , adresse
 serial.println("\nthe value , adress of intvar:");
 printvariable("intvar",intvar);
 
 serial.println("\nread nonexistent location -1 in intarray");
 printvariable("intarray[-1]",intarray[-1] );
 
 //the below print identical values , adresse
 serial.println("\nthe value , adress of intarray2:");
 printvariable("intarray2[0]",intarray2[0]);
 
 serial.println("\nread nonexistent location 4 in intarray");
 printvariable("intarray[4]",intarray[4] );
 
}
 
void loop(){}


quote

the values , adresses of intarray:

0: intarray - value: 1, @ adress: 1250

1: intarray - value: 2, @ adress: 1252

2: intarray - value: 3, @ adress: 1254

3: intarray - value: 4, @ adress: 1256


the value , adress of intvar:

intvar - value: -4, @ adress: 1248


read nonexistent location -1 in intarray

intarray[-1] - value: -4, @ adress: 1248



the value , adress of intarray2:

intarray2[0] - value: -5, @ adress: 1258


read nonexistent location 4 in intarray

intarray[4] - value: -5, @ adress: 1258



could lead nasty bugs.


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > What value will the it return?


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums