0
fn sum(x: &[u8]) -> usize {
    let mut tot = 0;
    for i in 0..10 {
        tot += x[i] as usize
    }
    return tot;
}

fn func(y: &[u8]) -> usize {
    let tot = sum(&&&&y);     /* Look here! */
    return tot;
}

fn main() {
    let w: [u8; 10] = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
    let tot = func(&w);
    println!("{}", tot);
}

This program works identically irrespective of the number of &'s where indicated. Whats going on, and what is the correct syntax?

Shepmaster
  • 274,917
  • 47
  • 731
  • 969
  • 3
    Probably a duplicate of http://stackoverflow.com/q/28519997/155423. – Shepmaster Jun 21 '16 at 14:05
  • 1
    There's a number of [idiomatic changes that you should make](https://play.rust-lang.org/?gist=4bc8b01537550436846d9ea65d7e83ce&version=stable&backtrace=0)(implicit returns, avoiding array indexing, avoiding explicit types). Additionally, if the code compiles and does what you want, that certainly seems like "correct syntax" to me. – Shepmaster Jun 21 '16 at 14:08

0 Answers0