ADVERTISEMENT
ADVERTISEMENT

Rust program to create a variable to store data in the HEAP area

Rust Example: Write a program to create a variable to store data in the HEAP area.
Submitted by Nidhi, on November 25, 2021

Problem Solution:

In this program, we will create a variable that will allocate space into the HEAP area of memory using the Box::new() function and print the result.

Program/Source Code:

The source code to create a variable to store data in the HEAP area is given below. The given program is compiled and executed on UBUNTU 18.04 successfully.

// Rust program to create a variable 
// to store data in the HEAP area

fn main() {
   let number = Box::new(5); 
   println!("Number: {}", number);
}

Output:

Number: 5

Explanation:

In the main() function, we used Box::new() function to create a variable in the HEAP area of memory. After that, we printed the value of the variable.

Rust Miscellaneous Programs »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.