belongs to collection: Rust Arrays Programs
In this program, we will create an integer array using the existing array and then print both arrays.
Program/Source Code:
The source code to create an array using the existing array is given below. The given program is compiled and executed successfully.
// Rust program to create an array // using existing array fn main() { let mut arr1:[i32;5] = [1,2,3,4,5]; let mut arr2=arr1; println!("Array1 : {:?}",arr1); println!("Array2 : {:?}",arr2); arr2[0] = 9; println!("\nArray1 : {:?}",arr1); println!("Array2 : {:?}",arr2); }
Output:
Array1 : [1, 2, 3, 4, 5] Array2 : [1, 2, 3, 4, 5] Array1 : [1, 2, 3, 4, 5] Array2 : [9, 2, 3, 4, 5]
Explanation:
Here, we created array arr2 using the existing array arr1. Then we modified the 1st element of arr2. After that, we printed the elements of both arrays.
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Program/Source Code:
The source code to create an array using the existing array is given below. The given program is compiled and executed successfully.
Output:
Explanation:
Here, we created array arr2 using the existing array arr1. Then we modified the 1st element of arr2. After that, we printed the elements of both arrays.
need an explanation for this answer? contact us directly to get an explanation for this answer