Last active
October 13, 2019 04:33
-
-
Save gusdelact/33a3d66d3da5e49dea0a2918d4544f1b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn llenar(dato : &mut u8) { | |
*dato = 0x20; | |
} | |
fn recorrer(arr: &[u8]) { | |
let mut i=0; | |
while i < arr.len() { | |
print!(" {} ", arr[i]); | |
i = i + 1; | |
} | |
} | |
fn main() { | |
//arreglo den 10 bytes | |
let mut arreglo: [u8; 10]= [0; 10];; | |
let mut i = 0; | |
let mut dato:u8=101; | |
//llenar al arreglo | |
while i<10 { | |
arreglo[i] = dato + 1; | |
println!("{:p}", &arreglo[i]); | |
i = i + 1; | |
dato = dato + 10; | |
} | |
println!("{:?}",arreglo); | |
//llenar al arreglo usando un apuntador | |
let mut dato:u8=141; | |
i = 0; | |
while i<10 { | |
let ptr = &mut arreglo[i]; | |
*ptr = dato + 1; | |
println!("{:p}", ptr); | |
i = i + 1; | |
dato = dato + 1; | |
} | |
println!("{:?}",arreglo); | |
i = 0; | |
while i<10 { | |
llenar(&mut arreglo[i]); | |
i = i + 1; | |
} | |
println!("{:?}",arreglo); | |
println!("array size: {}", arreglo.len()); | |
let slice:&[u8]= &arreglo; | |
recorrer(slice); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment