You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// 可以正确编译: cargo buildlet index = 10;let element = a[index];println!("The value of element is: {}", element);// 编译报错:cargo buildprintln!("a[0] is: {}, a[6] is: {}", a[0], a[6]);// error: index out of bounds: the len is 5 but the index is 6let element = a[10];println!("The value of element is: {}", element);
思考?
为什么声明了一个变量值,然后通过这个变量值去取超过数组的索引时,不会报错。而直接使用常量值或明确的值时,会编译报错?
这个应该是跟编译器有关。
The text was updated successfully, but these errors were encountered: